Simple code I’ve got attached to an empty game object in my scene, however the cursor does not become confined in either the editor or a build. Here is the code:
I had some similar problems with 5.3.1p1 and I made the following observations:
Transitioning from Locked to Confined does not work without first transitioning to None. The lockState will report correctly, but the behavior will be for the cursor to just jiggle in the center of the screen.
Cursor.lockState = CursorLockMode.Locked;
…
if (Cursor.lockState != CursorLockMode.Confined) {
//Going directly from Locked to Confined does not work
Cursor.lockState = CursorLockMode.None;
Cursor.lockState = CursorLockMode.Confined;
}
…
Transitioning to Locked automatically hides the cursor
I know that this isn’t 100% the same as your problem, but I think the issue is at least semi-related and your question came up when I Googled the problem.
Try changing the Escape key to another button. Escape usually unlocks the cursor by default in the web player. And cursor doesn’t really work the way it should in the editor so if you want to test out cursors, you should usually try it on a build.
None of the answers helped me, but later I found out this code works like a charm. Whenever u want to fix it, do a coroutine with FixMouse. Don’t know why this code works specifically for 2 * Time.deltaTime