Changes in EnemyMover

Hi,
I’m looking at the script you added to the GitHub folder of this lecture and I don’t understand how it should be built.
In the lecture we changes the path and put the tag only on the parent (and changes the code accordingly), now I’m looking at the GitHub and see this code:

//GameObject[] waypoints = GameObject.FindGameObjectsWithTag("Path");
GameObject[] tiles = GameObject.FindGameObjectsWithTag("Path");

//foreach(GameObject waypoint in waypoints) 
foreach(GameObject tile in tiles) 
{
    //path.Add(waypoint.GetComponent<Waypoint>());
    Waypoint waypoint = tile.GetComponent<Waypoint>();

    if(waypoint != null)
    {
        path.Add(waypoint);
    }
}

Does that mean that we left everything as it was and just renamed the wayspoints list to tiles? Should I add the path tag to all of the path tiles instead of their parent? Got really confused.

Hi TalBarda,

I’ve just checked the commit of this lecture in Gary’s repository, and you are right. It seems as if Gary forgot to include all changes in his commit.

The code you commented out is the code you need. Only the parent game object is supposed to have the “Path” tag. The children must not have the “Path” tag.

The reasoning behind the changes is the following: GameObject.FindGameObjectsWithTag("Path"); returns objects in a random order. We want the same order as in our Hierarchy. That’s why we look for the parent. Then we are able to iterate over the children of that parent.

Based on this idea, you could challenge yourself and try to make it work yourself. If you just want to see the final code for FindPath(), please jump to minute 4:19 in the video.

Did this help? :slight_smile:


See also:

1 Like

Yes, thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms