ABSTRACT

Jumping ahead in the script, take a look at GetTransforms() function now so that it is clear what happens when this class first starts: public void GetTransforms() { // we store all of the waypoints transforms in an ArrayList, // which is initialised here (we always need to do this

// before we can use ArrayLists) transforms=new ArrayList();

To make the waypoints control script easy to use, we need to make sure that our waypoints are set up in a particular way in the scene where we want to use them. This format is an empty gameObject with the WaypointsController.cs component attached to it, with all waypoints as its children. The waypoints controller script expects to find all of the waypoints it is going to use, as child objects under it. All of the transforms found in the GetTransforms() function are added to an ArrayList variable named transforms like this: foreach(Transform t in transform) { // add this transform to our arraylist transforms.Add(t); } totalTransforms=(int)transforms.Count; }

At the end of GetTransforms, we store the total number of transforms in an integer for easy access later on (so that we don’t have to count the ArrayList each time we need to know how many transforms it contains).