connect with my chase code code example

Example: connect with my chase code

public class Petrol : MonoBehaviour
{
    public float speed;
    private float waitTime;
    public float startWaitTime;

    public Transform[] moveSpots;
    private int randomSpot;

    void Start()
	{
        waitTime = startWaitTime;
        randomSpot = Random.Range(0, moveSpots.Length);
	}

    void Update()
    {
        transform.position = Vector3.MoveTowards(transform.position, moveSpots[randomSpot].position, speed * Time.deltaTime);

        if (Vector3.Distance(transform.position, moveSpots[randomSpot].position) < 0.2f)
		{
            if(waitTime <= 0)
			{
                randomSpot = Random.Range(0, moveSpots.Length);
                waitTime = startWaitTime;
			} else
			{
                waitTime -= Time.deltaTime;
			}
		}
    }
}

Tags:

Misc Example