I am currently using the IEnumerator function to pause a for loop, in which a ball should move towards another game object. From my print statements it seems like the ball moves a little, but it's actually never reaching the object and I'm not sure why. I have never used IEnumerator so I'm not sure if this is a part of the issue.
public IEnumerator CoUpdate(){
float waitTime = 8;
yield return new WaitForSeconds (waitTime);
for (int i = 0; i <= 19; i++) {
//Finding Game Objects
numbers = GameObject.FindGameObjectsWithTag ("num");
ball = GameObject.FindGameObjectWithTag ("ball");
float step = speed * Time.deltaTime * 2;
//Picking the random cube
index = Random.Range (0, numbers.Length);
pickedNumber = numbers [index];
print ("number picked");
print (pickedNumber.name);
print ("numer postion");
print (pickedNumber.transform.position);
//Moving ball to cube
target = pickedNumber.transform;
ball.transform.position = Vector3.MoveTowards(transform.position, target.position, step);
//Checking balls position
print ("ball Position");
print (ball.transform.position);
//Pause here
print ("PAUSE!");
yield return new WaitForSeconds (waitTime);
//Ball Returns to position
ball.transform.position = new Vector3 (0, 0, 0);
print ("ball reset");
print (ball.transform.position);
}
}