- Home /
yield WaitForSeconds not working
I have this simple code but the yield doesn't work at all. I dont get any errors.
function scoreShow ()
{
GameObject.Find("Score").GetComponent(score).score();
Debug.Log("function is initiating");
gameObject.guiText.enabled = true;
yield WaitForSeconds(1);
Debug.Log("yield successful");
gameObject.guiText.enabled = false;
}
@Reafy Do you launch your Coroutine? And in what function?
this is where the function is called
function Update () { if (Health <= 0) { Dead (); GameObject.Find("+1").GetComponent(killScore).scoreShow(); } }
its in a seperate script
Answer by Kiwasi · Oct 10, 2014 at 07:34 AM
I'll bet you all my Karma that your Dead method contains the line
Destroy(gameObject);
Once the GameObject that calls the coroutine is destroyed all of its coroutines stop execution.
Soultion is to call the coroutine from the killScore class. Make a wrapper method on killScore that starts the coroutine. Call that instead of the coroutine.
Guess what? You're keeping all your karma because you're right. I didn't know Destroy(gameObject); stopped all coroutines thanks for that :)