- Home /
Hide Cursor Problems
Hello, so im a noob at this and im having problems, I have this script that I want to hide and lock the cursor on startup, and unlock and show the cursor when I press escape. But heres the problem, after I press escape to unlock and show, and I press escape to lock and hide the cursor again, it only hides the cursor and doesnt lock it in place, what am I doing wrong?
var showingMouse : boolean;
function Start () {
showingMouse = false;
Screen.showCursor = false;
Screen.lockCursor = true;
}
function Update () {
//if escape is pressed, unlock cursor and show cursor
if (Input.GetButtonDown("Esc") && showingMouse == false){
showingMouse = true;
Screen.showCursor = true;
Screen.lockCursor = false;
}
else if (Input.GetButtonDown("Esc") && showingMouse == true){
showingMouse = false;
Screen.showCursor = false;
Screen.lockCursor = true;
}
}
Answer by TimBorquez · Jan 20, 2014 at 08:01 PM
lock cursor should hide and center the cursor
remember that lock cursor wont work exactly right in the editor, only in the build
try this code to just toggle it
if (Input.GetButtonDown("Esc"))
{
Screen.lockCursor = !Screen.lockCursor;
}
Your answer
Follow this Question
Related Questions
avatar making 0 Answers
Events triggered by button pressed. 2 Answers
Help with the update function and rigidbodys 3 Answers
Particle effect instantiate problem. 1 Answer