- Home /
Pause Menu Help?
Hey, I was wondering if someone could please point me to information to help me design a pause menu, and or a script for it? Thanks a bunch! Have a good day.
Thank you guys very much! I sadly won't be able to try this out for a while, however I'm anxious to try this out! Have a good day!
Answer by janzdott · Apr 05, 2013 at 04:33 PM
Have a bool variable isPaused. When you pause the game, set isPaused to true and set Time.timeScale = 0. When isPaused == true, draw your GUI. When you resume, set isPaused = false, and Time.timeScale = 1.
setting timescale is always dangerous, and setting it to zero is particularly dangerous. you have to really know what you're doing. search on here for many questions about it, you can easily divide by zero, and many other problems.
A divide by zero error would occur if you divide something by the timeScale. Why would you need to do that? And it has never caused a problem for me.
Answer by max98 · Apr 05, 2013 at 06:45 PM
You can add a gui button for pausing the game. When press stop all the update function associate with the game-loop. For example:
GamePause = false;
void OnGUI(){
if(GamePause){
GUI.Label(new Rect(0,0,Screen.width,Screen.height),"");
if(GUI.Button(new Rect(Screen.width * 0.8f,0, Screen.width * 0.2f,Screen.height * 0.1f),"Resume")){
GamePause = false;
}
}else{
if(GUI.Button(new Rect(Screen.width * 0.8f,0, Screen.width * 0.2f,Screen.height * 0.1f),"Pause")){
GamePause = true;
}
}
}
Use the GamePause variable in all your update function to check the game pause or resume. I hope this might help you.
Your answer
Follow this Question
Related Questions
Gui in Gui Not Working ? 1 Answer
Flash player slows down when unity player is installed 0 Answers
Assigned variable 1 Answer
Unity3D Crashes when baking terrain 1 Answer
Monodevelope auto complete problem? 1 Answer