I’m brazillian, don’t look for error in my text
Hey Guys! I’m doing an 3D Isometric plataform game, and I’m having a problem with the pause menu. The Pause Menu works fine, but i want to when you enter in the menu, the cursor get unlocked and when you get out the menu, the cursor get locked again. This is the original pause menu code:
#pragma strict
var pause : boolean = false;
var pauseGUI : GUIText;
pauseGUI.enabled = false;
function Update(){
if(Input.GetKeyUp(KeyCode.Escape)) {
if(pause==true){
pause = false;
}
else {
pause = true;
}
if(pause == true) {
Time.timeScale = 0.0;
pauseGUI.enabled = true;
}
else {
Time.timeScale = 1.0;
pauseGUI.enabled = false;
}
}
}
So i changed to this:
#pragma strict
var pause : boolean = false;
var pauseGUI : GUIText;
pauseGUI.enabled = false;
function Update(){
if(Input.GetKeyUp(KeyCode.Escape)) {
if(pause==true){
pause = false;
}
else {
pause = true;
}
if(pause == true) {
Screen.lockCursor = false;
Time.timeScale = 0.0;
pauseGUI.enabled = true;
}
else {
Time.timeScale = 1.0;
pauseGUI.enabled = false;
Screen.lockCursor = true;
}
}
}
When I press ESCAPE, the menu open and the cursor is unlocked. But when i press ESCAPE again, the menu close and the cursor still unlocked! This is the ULTRA basic code I made to lock the cursor when open scene:
#pragma strict
function Start () {
Time.timeScale = 1.0;
Screen.lockCursor = true;
}
function Update () {
}
Can someone help me? And explain why this happen? Thanks a lot!