- Home /
Locked and hidden cursor doesn't stay hidden
I have this script, the actual locking of the cursor is fine, it stays in the center and doesnt move, however the hiding of the cursor appears to be hidden, but whenever you press ANY key on the keyboard, it flickers(probably for a single frame), and then it goes hidden again. However when you are playing an fps and you are constantly pressing buttons, it constantly flickers and flickers. Here is the script, am I doing something incredibly idiotic or is there an underlying problem?
//Locking the cursor
if(Input.GetMouseButtonDown(0)){
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
if(Input.GetKeyDown(KeyCode.Escape)){
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
Did you test it in the actual build?
try to add in the line 9
else{
Cursor.lockState = CursorLock$$anonymous$$ode.Locked;
Cursor.visible = false;
}
Answer by Grizzly · Mar 30, 2015 at 06:52 AM
You could also try this one which I use by the way ,its the simplest and most used I belive.
function Start () {
Screen.lockCursor = true;
}
It will lock your cursor by default in the program version and you attach the script to the player camera also if you press esc ,it will unlock the cursor.
Your answer
![](https://koobas.hobune.stream/wayback/20220613191624im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Screen.lockCursor not working? 3 Answers
Screen lock with Text field 1 Answer
GUI text relative to screen? 1 Answer