- Home /
The question is answered, right answer was accepted
Coroutines Didn't Work After Changing Scene
Hi Everyone! I have this small problem and this problem starts to annoy me so I decided to ask a new question.
I have this scripts that simply gives the animation of typing text
IEnumerator ThxForPlayTextAnim() {
txtExit.text="";
txtGoodBye = "Thank You For Playing";
txtExit.gameObject.transform.localPosition = new Vector3(0,0,-0.61f);
for (int i = 0; i<txtGoodBye.Length;i++ ) {
if (i == 9)
txtExit.text += "\n";
else
txtExit.text += txtGoodBye[i].ToString();
yield return new WaitForSeconds(0.08f);
}
yield return new WaitForSeconds(0.5f);
Application.Quit();
}
I run this code and this works just as I wanted. But then After Changing Scene I noticed something strange.
The line where the yield return new WaitForSeconds(0.08f);
did not work and thus the animation within the loop. It freezes. I've been searching around seeking answers but I still can't find any
Can anyone tell me what's wrong?
Is the object that the Coroutine is on being destroyed when you change scene? (you can check this using its OnDestroy() function). If it's destroyed, its coroutines will be ter$$anonymous$$ated.
nope it is not destroyed, it is an entirely different coroutine in different scene. I have found the problem and solved it. But thank you so much for your response! I really appreciated it
Answer by Ibe · Feb 10, 2015 at 12:54 PM
I have found the problem, just if someone have the same problem.
The code works fine but not with the other script. I purposedly change the time.timescle in the previous scene to pause the game and the game transferred to the other scene having the time.timescale to be 0, making all coroutine to be stopped in the yield statement.
Adding the time.timescale = 1 fixed everything in my case
Thanks Ibe, thanks :D
I put Time.timeScale = 1 in Update Function and the scene WOR$$anonymous$$S!
Hello,
I have the exact problem but my timescale is still 1
Any other solution?
Are you sure that Bonfire-Bon's comment above doesn't apply to you? If not you should ask a seperate question since your problem clearly is not the same.