- Home /
Confusion on simple pause screen
Ok. I am making a simple pause screen. When the player presses Escape, I want it to show the word "Paused" (in the form of a GUIText) and show the cursor(I have Screen.lockCursor enabled in the begining). Here is the basic script I have so far: #pragma strict
public var PauseText : GUIText;
private var EscActive;
function Start ()
{
EscActive = false;
Screen.lockCursor = true;
PauseText.active = false;
}
function Update ()
{
if(Input.GetKey(KeyCode.Escape) && EscActive == false)
{
EscActive = true;
Screen.lockCursor = false;
PauseText.active = true;
}
if(Input.GetKeyDown(KeyCode.Escape) && EscActive == true)
{
EscActive = false;
Screen.lockCursor = true;
PauseText.active = false;
}
}
So, what is your problem? What is your question
Pausing a game can be done with: Time.timeScale = 0 (unpause = 1).
P.S. Little programmers tip: in your if-statement, when using a boolean you don't have to compare it to another boolean. EscActive == true is the same as EscActive. Or EscActive == false is the same as !EscEscape.
Awesome. Thanks for the tips! I had a small blank on how to freeze the time. :D
Sadly, though, I am still having a similar problem. It won't bring up the text or pause the game. Here is the updated code (I am at a brick wall :\ ):
#pragma strict public var PauseText : GUIText; private var EscActive; function Start () { EscActive = false; Screen.lockCursor = true; PauseText.active = false; } function Update () { if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape) && !EscActive) { EscActive = true; Screen.lockCursor = false; PauseText.active = true; Time.timeScale = 0; } if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape) && EscActive) { EscActive = false; Screen.lockCursor = true; PauseText.active = false; Time.timeScale = 1; } }
To be completely honest, it may be in the way I wrote the code that it messes up. I am not sure if I am confusing the computer or if I am putting in some wrong code the wrong way.
Answer by Tonyx97 · Aug 24, 2014 at 02:29 PM
You can try show the text with a simple OnGUI function like this:
function OnGUI ()
{
if (!EscActive) return;
GUI.Label ( Rect (Screen.width/2, Screen.height/2, 100, 100), "Pause" );
}
Your answer
Follow this Question
Related Questions
Is a global static boolean a good implementation for pausing my game? 2 Answers
Making a pause menu resume 2 Answers
Is it a BUG? Cursor Lock FS Mode in Mac Safari 1 Answer
Mouse cursor doesn't lock Unity 5 0 Answers
boolean flicker 3 Answers