Beispiel #1
0
    void PickRandomNode()
    {
        //print("Picking node");
        atRandomNode = false;
        while (!haveRandomNode)
        {
            int upperX = grid.width;
            int upperY = grid.height;

            int randX = Random.Range(0, upperX);
            int randY = Random.Range(0, upperY);

            if (grid.grid[randX, randY].cType == WorldGrid.CellType.AIR)
            {
                LinkedList <WorldGrid.Cell> path;
                randomNode     = new Vector2(randX, randY);
                haveRandomNode = true;
                //print("AI current pos: ("+grid.WorldToGrid(transform.position)+")");
                path = grid.AStar(randomNode, transform.position, 4);
                //print("AI path first node pos: ("+path.First.Value.x+","+path.First.Value.y+")");
                //print("AI current pos: ("+grid.WorldToGrid(transform.position)+")");
                LerpPath(path);
            }
        }
    }