How to move to point C?

Hi. I want to make my enemy to travel from Point A > B > C
Currently i only know to make it move from A to B.
How do i do that?

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour {


    public Transform A;
    public float speed;


    void Update()
    {
        float step = speed * Time.deltaTime;
        transform.position = Vector3.MoveTowards(transform.position, A.position, step);

    }
}

store the points you want to go to in a list
add a check “am I close enough to A”, if you are, update A to be the next point in the list

depending on what kind of pattern you want you can then remove that point from the list, remove it and add it to the end of the list (might want to consider a Queue instead of a list in that case).

1 Like