x


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

more ▼

asked Mar 05 '11 at 04:50 PM

Xedfire 1 gravatar image

Xedfire 1
158 13 14 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You could try using

WaitForSeconds(variable);

^this will pause time for a bit i guess

http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html

more ▼

answered Jul 26 '12 at 11:06 AM

lingai gravatar image

lingai
0 2 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x385
x261
x104
x83

asked: Mar 05 '11 at 04:50 PM

Seen: 1135 times

Last Updated: Jul 26 '12 at 11:06 AM