public IEnumerator StartExecution(int diceValue)
    {
        List <List <GameObject> > lst2D_GroundUnits = FindObjectOfType <PathGenerator>().GetComponent <PathGenerator>().lst2D_GroundUnits;

        for (int i = 0; i < diceValue; i++)
        {
            // get the player positin find corrosponding cube extract the data and then move according to the data.
            Vector2Int         initialPosition = new Vector2Int((int)transform.position.x, (int)transform.position.z);
            cubeItemProperties cip             = lst2D_GroundUnits[initialPosition.y][initialPosition.x].transform.GetComponent <cubeItemProperties>();
            if (cip.isFinal)
            {
                //this player has won the game
                finalPanel.SetActive(true);
                Text tmptext = finalPanel.transform.GetChild(0).GetComponent <Text>();
                tmptext.text = gameObject.name + " has Won The match!!!";
            }
            else
            {
                yield return(StartCoroutine(DoMotionOfPlayer(cip.cubeCurrentMotion)));
            }
        }


        Vector2Int         initialPosition2 = new Vector2Int((int)transform.position.x, (int)transform.position.z);
        cubeItemProperties cip2             = lst2D_GroundUnits[initialPosition2.y][initialPosition2.x].transform.GetComponent <cubeItemProperties>();

        if (cip2.isPitfall || cip2.isShortcut)
        {
            yield return(StartCoroutine(MovePlayerPosition(cip2.exitPoint)));
        }
        Dice.isDiceRolling = false;
    }
Exemplo n.º 2
0
    private void GenerateGridOfSize(int n)
    {
        groundUnit      = GameObject.CreatePrimitive(PrimitiveType.Cube);
        groundUnit.name = "GroundUnit";
        bool isMovingRight = true;

        for (int i = 0; i < n; i++)
        {
            List <GameObject> lst_GroundUnits = new List <GameObject>();
            for (int j = 0; j < n; j++)
            {
                lst_GroundUnits.Add(Instantiate(groundUnit, transform));
                lst_GroundUnits[j].GetComponent <MeshRenderer>().material = mat_cubeBoarder;
                lst_GroundUnits[j].tag = "NonWalkable";
                DestroyImmediate(lst_GroundUnits[j].GetComponent <BoxCollider>());
                cubeItemProperties cip = lst_GroundUnits[j].AddComponent <cubeItemProperties>();

                if (i == 0 && j == 0)
                {
                    cip.isInitial = true;
                }

                else if (i == 7 && j == 0)
                {
                    cip.isFinal = true;
                }

                if (isMovingRight)
                {
                    cip.cubeCurrentMotion = MotionType.right;
                    if (j == n - 1)
                    {
                        cip.cubeCurrentMotion = MotionType.fwd;
                    }
                }
                else
                {
                    cip.cubeCurrentMotion = MotionType.left;
                    if (j == 0)
                    {
                        cip.cubeCurrentMotion = MotionType.fwd;
                    }
                }


                // special abilityies cubes.
                // two shortcuts and two pitfalls


                lst_GroundUnits[j].transform.position = new Vector3(j, 0, i);
            }
            lst2D_GroundUnits.Add(lst_GroundUnits);
            isMovingRight = !isMovingRight;
        }
        DestroyImmediate(groundUnit);
    }
 public IEnumerator StartExecution(float timeDelay)
 {
     for (int i = 0; i < pathGeneratorScript.lst2D_GroundUnits.Count; i++)
     {
         for (int j = 0; j < pathGeneratorScript.lst2D_GroundUnits[i].Count; j++)
         {
             cubeItemProperties cip = pathGeneratorScript.lst2D_GroundUnits[i][j].GetComponent <cubeItemProperties>();
             if (!cip.isFinal)
             {
                 yield return(StartCoroutine(DoMotionOfPlayer(cip.cubeCurrentMotion)));
             }
         }
     }
 }