- Home /
Pause Menu Problem
I am in the process of releasing an update for my game. I'm trying to make a pause menu, but it is not working like I would really prefer it to. The problem isn't game-breaking, but it is a pain. Basically, when pause is activated by pressing escape, the timescale is set to 0, so everything stops. BUT, if the player keeps spamming the escape key, the time stutters forward. Here is my code:
var level : int; var check : boolean = false; var doWindow0 : boolean = false;
function DoWindow0 (windowID : int) { if(GUI.Button (Rect (10,30, 150,20), "Back to Menu")) Application.LoadLevel(level);
if(GUI.Button (Rect (10,50, 150,20), "Return to Game"))
{
BackToGame();
}
}
function OnGUI () {
if (doWindow0)
window = GUI.Window (0, Rect (Screen.width / 2 - 90,Screen.height / 2 - 45,180,90), DoWindow0, "Pause Menu");
}
function Update() {
//I tried to use all of the button events...
if(Input.GetButtonUp("Esc"))
{
doWindow0 = true;
Screen.lockCursor = false;
Screen.showCursor = true;
Time.timeScale = 0;
}
if(Input.GetButtonDown("Esc"))
{
doWindow0 = true;
Screen.lockCursor = false;
Screen.showCursor = true;
Time.timeScale = 0;
}
if(Input.GetButton("Esc"))
{
doWindow0 = true;
Screen.lockCursor = false;
Screen.showCursor = true;
Time.timeScale = 0;
}
}
function BackToGame() { Screen.lockCursor = true; Screen.showCursor = false; doWindow0 = false; Time.timeScale = 1.0; }
Attach this script to a first person controller prefab and try it out for yourself. Any kind of solution would be appreciated.
If you want to actually play the game that I'm working on (and see if the pause menu update was finished), go here: http://www.kongregate.com/games/Xedfire/island-jumper
Answer by lingai · Jul 26, 2012 at 11:06 AM
You could try using
WaitForSeconds(variable);
^this will pause time for a bit i guess
http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html
Your answer
Follow this Question
Related Questions
Pause menu doesn't pause everything 0 Answers
Resume Game with Timescale + Score? 1 Answer
hi i just got the ultimate fps camera and it is not compatible with pausemenus 0 Answers
Pause menu... Isn't pausing everything... 1 Answer
How to Appease a pause menu in a game that changes it's time scale? 1 Answer