I have written a script that is supposed to make an enemy go back and forth between control points but it doesn’t work. Any ideas?
Heres the script:
using UnityEngine;
using System.Collections;
public class NavTest : MonoBehaviour
{
public Transform target1;
public Transform target2;
NavMeshAgent agent;
void Start ()
{
agent = GetComponent<NavMeshAgent> ();
}
void LateUpdate ()
{
StartCoroutine ("Patrol1");
StartCoroutine ("Patrol2");
}
IEnumerator Patrol1 ()
{
agent.SetDestination (target1.position);
yield return new WaitForSeconds (0.5f);
}
IEnumerator Patrol2 ()
{
agent.SetDestination (target2.position);
yield return new WaitForSeconds(0.5f);
}
}
It goes to the first point but doesn’t go to the second point.