- Home /
Level completed but still playable (timescale problem)
I'm working on a game in which, after you complete a level, a GUI box (called in onGUI) pops up showing you the score, and a few options. That all works great.
The problem here is, when I finish the level, I am still able to move my character around and play as though nothing happened.
The way to fix this which I thought was, that I could add Time.timescale = 0; at the place where I check if you completed the level or no. But this method didn't work, as when the next level is loaded, or when any of the options are chosen, the timescale doesn't return to 1.
I tried putting time.timescale = 1, whenever you click on an option, but still no use.
Here is my code:
void OnGUI()
{
PlayerPrefs.SetInt("levellock" + (currlevel), 1);
if(levelcomplete)
{
Time.timeScale = 0;
GUI.Box (new Rect (Screen.width*1/8,Screen.height*1/8,Screen.width*3/4,Screen.height*10/14),congobase);
//Go to next level
if (GUI.Button (new Rect (Screen.width*7/20,Screen.height*3/8 ,Screen.width/3 ,Screen.height/8),gonextLevel))
{
Time.timeScale = 1;
Application.LoadLevel(currlevel+1);
print("next level");
}
//Go to Level Selection menu
if (GUI.Button (new Rect (Screen.width*7/20,Screen.height*4/8 ,Screen.width/3 ,Screen.height/8),golevelSelect))
{
Time.timeScale = 1;
Application.LoadLevel(0);
print("level select");
}
//Play this level again/Refresh
if (GUI.Button (new Rect (Screen.width*7/20,Screen.height*5/8 ,Screen.width/3 ,Screen.height/8),doRefresh))
{
Time.timeScale = 1;
Application.LoadLevel(currlevel);
}
Basically what I want is, the game to pause when the menu overlay comes up, and the next level to load smoothly as it should load normally.
is this object marked as [DontDestroyOnLoad()][1]?
if so then does levelcomplete get set to false anywhere?
[1] http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html
Sorry, but why not just disable the player input with a simple bool value , for example?
I agree with @ShadoX - setting timeScale to 0 causes more issues that you need to workaround than it solves. I reserve timeScale = 0 only to my pause menu, and in my next game I will look for other options, as I don't like it even for that.
I would look for other solution - either stopping all the moving parts in the scene (use Send$$anonymous$$essage or C# events or some other broadcast mechanism to notify them) or destroying them.
Alright guys, got this to work by setting Timescale to 0 on level complete, and changed the first line of code in the level load to timescale = 1. Worked. Want to know if this is a good method or no? And what could be the potential problems with this.
Your answer
Follow this Question
Related Questions
Draw GUI Text if clicked out of webplayer 1 Answer
Timer Pause 1 Answer
how do I make it so that my game only starts after the player presses Jump? 0 Answers
Pause a Particle Effect? 1 Answer