I have a C# script called “EnemyAI”. This is the entire script:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour
{
public Transform checkPoint1;
public Transform checkPoint2;
public Transform checkPoint3;
public Transform checkPoint4;
public NavMeshAgent nav;
void Awake ()
{
nav = GetComponent<NavMeshAgent> ();
}
void Start ()
{
nav.SetDestination (checkPoint1.position);
}
void Update ()
{
if (nav.destination == checkPoint1.position)
{
nav.SetDestination(checkPoint2.position);
}
if (nav.destination == checkPoint2.position)
{
nav.SetDestination (checkPoint3.position);
}
if (nav.destination == checkPoint3.position)
{
nav.SetDestination(checkPoint4.position);
}
if (nav.destination == checkPoint4.position)
{
nav.SetDestination(checkPoint1.position);
}
}
}
The problem is that when I run the game in the editor, the object sits still. Even though it has a “NavMeshAgent” component on it, the script doesn’t work. Any ideas? Thanks!