Пример #1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 celledPosition = transform.position;

        if (Input.GetKey(KeyCode.W) && speedTimer.Finished && !levelGenerator.CheckTheWall(XPozition, YPozition, Side.Up))
        {
            celledPosition     += Vector3Int.up;
            speedTimer.Duration = 1f / speed;
            speedTimer.Run();
        }
        else if (Input.GetKey(KeyCode.S) && speedTimer.Finished && !levelGenerator.CheckTheWall(XPozition, YPozition, Side.Down))
        {
            celledPosition     += Vector3Int.down;
            speedTimer.Duration = 1f / speed;
            speedTimer.Run();
        }
        else if (Input.GetKey(KeyCode.A) && speedTimer.Finished && !levelGenerator.CheckTheWall(XPozition, YPozition, Side.Left))
        {
            celledPosition     += Vector3Int.left;
            speedTimer.Duration = 1f / speed;
            speedTimer.Run();
        }
        else if (Input.GetKey(KeyCode.D) && speedTimer.Finished && !levelGenerator.CheckTheWall(XPozition, YPozition, Side.Right))
        {
            celledPosition     += Vector3Int.right;
            speedTimer.Duration = 1f / speed;
            speedTimer.Run();
        }
        transform.position = celledPosition;
    }
Пример #2
0
    // Update is called once per frame
    private void Update()
    {
        if (speedTimer.Finished && GameObject.FindObjectOfType <Player>() != null)
        {
            List <Cell> listCells = new List <Cell>();

            for (int counter = 0; counter < 4; counter++)
            {
                int xNext = XPozition;
                int yNext = YPozition;
                switch ((Side)counter)
                {
                case Side.Up:
                    yNext++;
                    break;

                case Side.Right:
                    xNext++;
                    break;

                case Side.Down:
                    yNext--;
                    break;

                case Side.Left:
                    xNext--;
                    break;
                }

                if (!levelGenirator.CheckTheWall(XPozition, YPozition, (Side)counter))
                {
                    listCells.Add(CrateCellWithCorrectCost(xNext, yNext));
                }
            }
            listCells.Sort();

            bool busyCell = false;
            foreach (Enemy enemy in GameObject.FindObjectsOfType <Enemy>())
            {
                busyCell = listCells[0].XCell == enemy.XPozition && listCells[0].YCell == enemy.YPozition && enemy.gameObject != gameObject;
            }
            if (!busyCell)
            {
                transform.position  = new Vector3(listCells[0].XCell + 0.5f, listCells[0].YCell + 0.5f, 0);
                speedTimer.Duration = 1f / speed;
                speedTimer.Run();
            }
        }
    }