- Home /
Pause Button Freezing Game
Hey Everyone! So I have a pause button that has other levels that I access from it, whenever i click those levels, It freezes the game! I have attached a video of an example how. It is in my FPS shooter so when I go back to gameplay, the character is frozen too! The Options Screen, Store 1, and loadedLevel are all freezing... This is the script I have been using:
var isPaused : boolean = false;
function Update()
{
if(Input.GetKeyDown("p") && !isPaused)
{
print("p");
Time.timeScale = 0.0;
isPaused = true;
}
else if(Input.GetKeyDown("p") && isPaused)
{
print("Unpaused");
Time.timeScale = 1.0;
isPaused = false;
}
}
function OnGUI ()
{
if(isPaused)
{
// RenderSettings.fogDensity = 1;
if(GUI.Button (Rect (500,120,160,40), "Upgrades")){
Application.LoadLevel ("Store 1");
}
if(GUI.Button (Rect (500,160,160,40), "Main Menu"))
{
print("Main Menu");
Application.LoadLevel("IDKStart");
Time.timeScale = 1.0;
isPaused = false;
}
if(GUI.Button (Rect (500,200,160,40), "Options")){
Application.LoadLevel ("Options Screen");
}
if (GUI.Button (Rect (500,240,160,40), "Restart")) {
Application.LoadLevel (Application.loadedLevel);
}
}
}
@script AddComponentMenu ("GUI/Pause GUI")
And this is the video: http://www.youtube.com/watch?v=prXnjkWHX9E&feature=plcp
Can someone help me figure out/fix the problem? Thanks!!
You are setting the timeScale to 0 to pause it, in other words everything is frozen because time itself is.
By the way why are you loading a new scene for gui screens? Do you need help with designing the menu system?
Oh I see. For Some reason I was assu$$anonymous$$g that time starts again on a new level loading.. Thanks!!! Can you make that an answers so I can give you credit for it?
I just made it an answer... and thanks for giving me credit, I have helped about 7-8 people and no one gave me credit.
Yeah when a level is loaded it carries over the timeScale, I made that mistake myself before:)
Answer by TheVectorHunter · Aug 12, 2012 at 07:05 PM
You are setting the timeScale to 0 to pause it, in other words everything is frozen because time itself is.
By the way why are you loading a new scene for gui screens? Do you need help with designing the menu system?
I have different things that happen on the menus... So yeah. Thats why I have different scenes.
Your answer
Follow this Question
Related Questions
Why does Unity freeze for long periods when highlighting some objects in the hierarchy? 0 Answers
Unity is stuttering.. every 1.5 seconds about. 4 Answers
Make enemy wait before attacking player 2 Answers
Pausing the game after player object gets destroyed 1 Answer
Web Player crashes in Pause Menu 1 Answer