- Home /
Unity 5.1.1f1 - WebGL : Lock cursor in the screen not working
Hello everyone. I'm working on a game project on Unity 5.1.1f1 and I had to build it on the WebGL platform. In my game management script, I lock the cursor in the screen with the code below. It works in the editor but not after the build and the integration on the website. So when I want to turn the camera on a side, it is sometimes blocked.
It seems to be a recurrent problem on this forum, so I wonder if it is a Unity general problem (because of the new version) or this comes from my code ?
Here's my code.
private bool lockCursor;
void Start() {
lockCursor = true;
}
void OnGUI () {
if (Input.GetKeyDown (KeyCode.Escape))
lockCursor = false;
if (lockCursor) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
else {
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
}
Thank you very much.
Answer by Schubkraft · Jul 13, 2015 at 02:56 PM
This is a bug in the current version. Sorry for the troubles.
You can follow it at http://issuetracker.unity3d.com/issues/webgl-cursor-dot-lockstate-does-not-work-as-expected
Answer by Reincarnate · Mar 19, 2018 at 05:50 PM
The mouse lock keeps forcing me to look up on my chromebook . I need help with this,whenever I try to play a game, the mouse lock works, but when it locks it forces me to look up, I am so confused, anyone have a solution. because I'm playing these webgl games on my chromebook.
Your answer
![](https://koobas.hobune.stream/wayback/20220611230512im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lock the screen 1 Answer
Lock cursor everywhere not center,how? 1 Answer
Modifying the pause menu to have screen.lockcursor on at start 1 Answer
Playerprefs.setInt generates errors in webGL 0 Answers
lock camera to when open popup screen 3 Answers