Now that the Enemy prefab is moving around on patrol, we need to get a reference to the player's position and change the destination of NavMeshAgent.
Add the following code to EnemyBehavior and hit Play:
public class EnemyBehavior : MonoBehaviour
{
// 1
public Transform player;
public Transform patrolRoute;
public List<Transform> locations;
private int locationIndex = 0;
private NavMeshAgent agent;
void Start()
{
agent = GetComponent<NavMeshAgent>();
// 2
player = GameObject.Find("Player").transform;
// ... No other changes needed ...
}
/* ... No changes to Update,
InitializePatrolRoute, or
MoveToNextPatrolLocation ... */
void OnTriggerEnter(Collider other)
{
if(other.name == "Player")
{
// 3
agent.destination = player...