Our enemy moves to the first patrol point just fine, but then it stops. What we want is for it to continually move between each sequential location, which will require additional logic in Update() and MoveToNextPatrolLocation(). Let's create this behavior.
Add the following code to EnemyBehavior and hit Play:
public class EnemyBehavior : MonoBehaviour
{
// ... No changes needed ...
void Start()
{
// ... No changes needed ...
}
void Update()
{
// 1
if(agent.remainingDistance < 0.2f && !agent.pathPending)
{
// 2
MoveToNextPatrolLocation();
}
}
void MoveToNextPatrolLocation()
{
// 3
if (locations.Count == 0)
return;
agent.destination = locations[locationIndex].position;
// 4
locationIndex = (locationIndex + 1) % locations.Count;
...