So here is the problem I want to change the position of gameObject to specific points that I declared with empty objects randomly but the problem is the moment the object reaches one of the points it starts shaking around and not doing the same thing again here is my code
public class EnemyController : MonoBehaviour {
public Transform[] movePoints;
public float speed;
private int amount;
private Transform currentTarget;
void Start () {
randoming ();
}
void Update () {
Movement ();
}
void randoming(){
amount = Random.Range (0, movePoints.Length);
currentTarget = movePoints[amount];
}
void Movement(){
transform.position = Vector3.MoveTowards (transform.position, currentTarget.position, speed * Time.deltaTime);
StartCoroutine (startMoving());
}
IEnumerator startMoving(){
yield return new WaitForSeconds (5.05f);
randoming ();
}
}