- Home /
Application.LoadLevel & Time.timeScale glitch
Hi, I have a simple game where I have a Pause function using Time.timeScale set to 0.0f - On the Pause screen I have a Restart button who tiggers Application.LoadLevel to load the same scene I'am currently running. This seems to work only every second time - It seems like not all my variables in the Void Start's is set properly.
The reason why I think this could have some things to do with the Time.timeScale, is that i have a Game Over screen where I do not set Time.timeScale and then use the Application.LoadLevel to restart the game and this works just fine.
I have tried to set the Time.timeScale to 1.0f before using the Application.LoadLevel but it is still not working.
Does anyone have a say about this or any ideas? - Is it a bad routine to use Application.LoadLevel to load the same current level as a Restart function?
/joe
Answer by kennypu · Apr 11, 2011 at 10:45 PM
i didn't really get your question, but seeing that its a timeScale problem, you have to set the timeScale back to 1 in the Start of the new scene. Try that, and it should work.
I am doing this in my void start - i have a script on an empty game object i call my Scene$$anonymous$$anager where i set things like this - my question is: Is it a bad routine to use Application.LoadLevel to load the same current level as a Restart function? because i use this and i experience glitches - i can try explaining in more depth, what is it you dont really understand?
when i load the scene again not all my variables in the void start is reset.
Not sure I understand here either? What do you mean by that your Start variables are reset? Can you show some code to clarify your question?
I have the exact same problem.
I pause the game with Time.timeScale = 0.0f. I restart the level by calling Time.timeScale = 1.0f, and then calling Application.LoadLevel("Game Scene"). The result is that the timeScale gets set to 1.0 only every second restart! Note that putting the resume call after doesn't help either.
Although the symptom can be resolved with some object that exists at the beginning of the scene call Time.timeScale = 1.0 in its Awake(), this is just a hack.
The question is: why doesn't Time.timeScale = 1.0 work right around an Application.LoadLevel()? And why does it work every second time?