So i have this enemy gameobject and i want it to move in a certain pattern like a patrol. So i want him to move from A to B to C then Back to B to A. The script I worked out makes him go from C to A directly but I dont want that. Can someone please help . The Length of PatrolPoint Array in 3 `using UnityEngine; using System.Collections;
public class EnemyPatrol : MonoBehaviour {
public Transform [] patrolPoints; // An Array of path points to be followed
private int currentPoint ;
public float enemySpeed ;
void Start()
{
currentPoint = 0;
transform.position = patrolPoints[ currentPoint].position; // Starting Point
}
void Update()
{
if(transform.position == patrolPoints[currentPoint].position)
{
currentPoint ++ ;
}
if(currentPoint >= patrolPoints.Length)
{
currentPoint = 0 ;
}
transform.position = Vector3.MoveTowards(transform.position , patrolPoints[currentPoint].position , enemySpeed*Time.deltaTime);
}
} `