Beispiel #1
0
    void Update()
    {
        if (isPaused)
        {
        }
        else if (path != null && !isPaused)
        {
            int currCell = 0;
            while (currCell < path.Count - 1)              // this while loop draw the path on console(scene view). Doesnt affect game view because it's debug
            {
                Vector2 start = new Vector2(path [currCell].x, path [currCell].y);
                Vector2 end   = new Vector2(path [currCell + 1].x, path [currCell + 1].y);
                Debug.DrawLine(start, end, Color.red);
                currCell++;
            }

            Vector2 tempNode = new Vector2(path [currentNode].x, path [currentNode].y);
            transform.position = Vector2.Lerp(transform.position, tempNode, speed);
            if (Vector2.Distance(transform.position, tempNode) <= 0.05f)
            {
                currentNode++;                //if the distance between current node and chaser's position is less than 0.05 then move on to the next node
            }
        }

        path = mg.Astar(getNodePosition(transform.position), getNodePosition(player.transform.position));
    }
Beispiel #2
0
	// Use this for initialization
	void Start()
	{
		mg = GameObject.Find ("Scripts").GetComponent<MazeGenerator> ();
		player = GameObject.FindGameObjectWithTag ("Player");
		point = GameObject.Find ("ref point").transform;
		currentNode = 0;
		path = mg.Astar(getNodePosition(transform.position), 0);
		point.position = new Vector2( mg.cells [0].x, mg.cells[0].y);
	}
Beispiel #3
0
 // Use this for initialization
 void Start()
 {
     mg             = GameObject.Find("Scripts").GetComponent <MazeGenerator> ();
     player         = GameObject.FindGameObjectWithTag("Player");
     point          = GameObject.Find("ref point").transform;
     currentNode    = 0;
     path           = mg.Astar(getNodePosition(transform.position), 0);
     point.position = new Vector2(mg.cells [0].x, mg.cells[0].y);
 }