Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (aStar)
     {
         List <Node> path = graph.AStar(node0, node7);
         foreach (Node node in path)
         {
             Debug.Log(node.id);
         }
         aStar = false;
     }
 }
Example #2
0
 //To use this, GetComponent
 public void ChangeEndNode(int node)
 {
     initial = graph.GetNearestNodeByCenter(character.transform.position);
     end     = node;
     if (initial != -1)
     {
         path = graph.AStar(graph.nodes[initial], graph.nodes[end]);
         path.RemoveAt(0);
     }
     if (path.Count != 0)
     {
         current = path[0].id;
         path.RemoveAt(0);
     }
 }
Example #3
0
    // Use this for initialization
    new void Start()
    {
        base.Start();
        //Get map graph
        GameObject map = GameObject.Find("Map Graph");

        graph   = map.GetComponent <GraphMap>();
        initial = graph.GetNearestNodeByCenter(character.transform.position);
        path    = new List <Node>();
        if (astar_target != null)
        {
            end     = graph.GetNearestNodeByCenter(astar_target.transform.position);
            path    = graph.AStar(graph.nodes[initial], graph.nodes[end]);
            current = path[0].id;
            path.RemoveAt(0);
        }
    }