public class Unit : MonoBehaviour{
public Vector3 CheckPoint;
public int NumCheckPoint = 0;
public Dictionary<int, Vector3> CheckPointsMove = new Dictionary<int, Vector3>();
private float speed = 2f;
private GameObject head;
void Start(){
head = gameObject.transform.Find("Head").gameObject;
CheckPointsMove[0] = new Vector3(2, 1, 2);
CheckPointsMove[1] = new Vector3(10, 1, 2);
CheckPointsMove[2] = new Vector3(10, 1, 13);
}
void Update(){
MoveEnemy();
}
void MoveEnemy(){
head.transform.LookAt(new Vector3(CheckPoint.x, 0, CheckPoint.z));
if(CheckPoint==transform.position){
++NumCheckPoint;
foreach(KeyValuePair<int, Vector3> v in CheckPointsMove){
if(v.Key == NumCheckPoint){
CheckPoint = v.Value;
}
}
}
transform.position = Vector3.MoveTowards(transform.position, CheckPoint, speed*Time.deltaTime);
}