I am trying to move a patrolling enemy from one patrol point to the next, but for some reason it only goes to the first patrol point in the Transform array, or element 0.
Here is the code for this enemy (under Update()):
if (shouldPatrol)
{
moveDirection = patrolPoints[currentPatrolPoint].position - transform.position;
if(Vector3.Distance(transform.position, patrolPoints[currentPatrolPoint].position) < .1f)
{
currentPatrolPoint++;
if(currentPatrolPoint >= patrolPoints.Length)
{
currentPatrolPoint = 0;
}
}
}
Here’s a screenshot of the enemy stuck in position 0. I turned debug on so you can see the “current patrol point” is stuck on 0.