So I have it set so that the boomerang goes to a random point. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Patrol : MonoBehaviour
{
public float speed;
public float range;
private float distToPlayer;
public Transform player;
public Transform[] moveSpots;
private int randomSpot;
private float waitTime;
public float startWaitTime;
void Start()
{
waitTime = startWaitTime;
randomSpot = Random.Range(0, moveSpots.Length);
}
void Update()
{ //start //finish
transform.position = Vector2.MoveTowards(transform.position, moveSpots[randomSpot].position, speed * Time.deltaTime);
if (Vector2.Distance(transform.position, moveSpots[randomSpot].position) < 0.2f)
{
if (waitTime <= 0)
{
randomSpot = Random.Range(0, moveSpots.Length);
waitTime = startWaitTime;
}
else
{
waitTime -= Time.deltaTime;
}
}
distToPlayer = Vector2.Distance(transform.position, player.position);
if (distToPlayer < range)
{
Destroy(gameObject);
}
}
}
So, how can I make it that it goes to one points first, then the other? Help!