I have the following script attached to a Sphere game object. When I run the game, the Sphere begins ascending and never stops. The truth value of itemBounceUp never changes. It seems that itemBounce() is never getting called, but I have no error messages and I can’t figure out why. I thought it might be the for-loop but I tried pulling it out to see if I could get itemBounce() to run though even once and the same thing happened.
Thanks,
Billy
using UnityEngine;
using System.Collections;
public class BounceScript : MonoBehaviour {
public float bouncespeed = 0.002f;
public bool itemBounceUp = true;
public void Start() {
itemBounce();
}
public void Update () {
if(itemBounceUp == true) {
this.transform.position = this.transform.position + new Vector3(0, bouncespeed, 0);
}
else if(itemBounceUp == false) {
this.transform.position = this.transform.position + new Vector3(0, -bouncespeed, 0);
}
}
public IEnumerator itemBounce () {
for(int i=1;i>0;i++) {
yield return new WaitForSeconds(0.2f);
itemBounceUp = false;
yield return new WaitForSeconds(0.2f);
itemBounceUp = true;
}
}
}