From what I’ve experienced (2019.3.0f3) Cursor.LockState has incorrect behavior that differs from the Editor and the Build.
Editor issue:
Changing from a LockState of Locked to Confined will have the cursor confined to the center of the Game view and can not be moved unless you press Escape. This can be avoided by calling a LockMode of None immediately before calling Confined, then the cursor will be confined to the Game view.
A Locked state will have an invisible cursor as expected when in Editor.
Build issue:
A LockState of Locked will lock the cursor to the center of the screen, but the cursor will remain visible. According to the Documentation, it should be invisible. Both Confined and None display the cursor and act as they should with regard to boundaries.
You can test it with this short script:
using UnityEngine;
public class CursorLockExample : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
Cursor.lockState = CursorLockMode.None;
if (Input.GetKeyDown(KeyCode.Alpha1))
Cursor.lockState = CursorLockMode.Locked;
if (Input.GetKeyDown(KeyCode.Alpha2))
Cursor.lockState = CursorLockMode.Confined;
// Workaround
if (Input.GetKeyDown(KeyCode.Alpha3))
{
Cursor.lockState = CursorLockMode.None;
Cursor.lockState = CursorLockMode.Confined;
}
}
}
It’s a small issue, but thought I’d share in case someone else ran into it.