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.
2 Answers
2Have 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.
– FattieA 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.
– janzdottYou 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.
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!
– wolfgang_1996