- Home /
yield WaitForRealSeconds
I am trying to make a unique waitForSeconds function that uses time.TimeSinceLevelLoad instead of time.Time. I am doing this because if time.timeScale is set to 0, the normal yield waitForSeconds coroutine never finishes.
For some reason though WaitForRealSeconds never ends and so the yield doesn't end.
function Start(){
Time.timeScale = 0;
yield WaitForRealSeconds(1);
Time.timeScale = 1;
}
function WaitForRealSeconds(time : float){
var current = Time.timeSinceLevelLoad;
while(Time.timeSinceLevelLoad - current < time){
yield;
}
}
have you tried timers/invokes or other things than yield to execute the Time.timeScale = 1; ?
Answer by Kryptos · Nov 21, 2012 at 03:20 PM
Time.timeSinceLevelLoad may also be affected by Time.timeScale, though this behaviour is not documented (but makes sense). Try using Time.realtimeSinceStartup instead.
Thanks man - have been looking for an answer for quite some time. Didn't know that Time.timeSinceLevelLoad was affected by time.Scale!
I did not know either. But it makes sense if you think at this value as a timer for a platform game for example. If the player pause the game, the timer should pause as well.
Your answer
Follow this Question
Related Questions
Last item not being moved (yield problem) 0 Answers
Coroutoutine doesnt work properly. 3 Answers
Getting an error when trying to yield 2 Answers