|
I'm running this coroutine: Under Update() in an attempt to always give the player an incorrect display of several stats. But, as it stands, running that changes the value so quickly that it hurts one's eyes. WaitForSeconds isn't doing anything to slow it down. What am I doing wrong?
(comments are locked)
|
The question has been closed Dec 15 '12 at 08:56 AM by burnpsy for the following reason:
The question is answered, right answer was accepted
|
The waitForSeconds is actually useless at this point. There is nothing after the yield statement. Coroutines run kind of parallel to your other code (not really parallel but almost ;) ). When you start a coroutine a new coroutine object is created which is handled by Unity's coroutine scheduler in the background. You can't halt or delay Update. Update will be called every frame. Whenever you use StartCoroutine you create a new independent instance of thie coroutine. You propably want something like that: This will start one coroutine which will run forever and that changes your variables once a second. That would do it. Thanks.
May 20 '12 at 07:53 PM
burnpsy
(comments are locked)
|

Are you calling RandomDisplay from Update? If so, WFS is working..but since new functions are continually called you will have X amount of WFS calls happening(which defeats the purpose). You can wrap the Update call with a boolean, then once the WFS has finished executing you can flip the bool back so the function will be called again.
WaitForSeconds can only pause coroutines - the caller code will not even notice the pause, because StartCoroutine returns almost immediately (the coroutine is automatically resumed each frame, and runs until it finds an yield instruction).