I have an enemy that, when not attacking the player, moves around in a certain pattern to search for the player. The problem is that when it reaches the final point of its pattern, it stops. I want it to reset and start going back to the first point, but I don’t know how that’s done.
Can anyone help me out? Here’s my script:
public var currentTarget : Transform;
public var targets : Transform[];
public var navigation : NavMeshAgent;
private var i : int = 0;
function Start ()
{
navigation.destination = targets[i].position;
}
function Update ()
{
var dist = Vector3.Distance(targets[i].position,transform.position);
currentTarget = targets[i];
if (dist < 2)
{
if (i < targets.Length - 1)
{
i++; //change next target
navigation.destination = targets[i].position;
}
}
}