Now that we understand the basics of procedural programming, it's time to get a reference to our patrol locations and assign them to a usable list:
- Add the following code to EnemyBehavior:
public class EnemyBehavior : MonoBehaviour
{
// 1
public Transform patrolRoute;
// 2
public List<Transform> locations;
void Start()
{
// 3
InitializePatrolRoute();
}
// 4
void InitializePatrolRoute()
{
// 5
foreach(Transform child in patrolRoute)
{
// 6
locations.Add(child);
}
}
void OnTriggerEnter(Collider other)
{
// ... No changes needed ...
}
void OnTriggerExit(Collider other)
{
// ... No changes needed ...
}
}
- Select Enemy and drag the Patrol Route object from the Hierarchy window onto the Patrol Route variable in EnemyBehavior:
- Hit the...