Esempio n. 1
0
    public List <Vector3> FindPath(Vector3 startPosition, Vector3 targetPosition)
    {
        int startX, startY;
        int endX, endY;

        _grid.GetXY(startPosition, out startX, out startY);
        _grid.GetXY(targetPosition, out endX, out endY);

        List <PathNode> pathNodes = FindPath(startX, startY, endX, endY);

        if (pathNodes != null)
        {
            List <Vector3> path = new List <Vector3>();
            foreach (PathNode pathNode in pathNodes)
            {
                path.Add(new Vector3(pathNode.X, pathNode.Y) * _grid.CellSize + Vector3.one * _grid.CellSize * .5f);
            }
            return(path);
        }
        else
        {
            return(null);
        }
    }