I know this is an old answer, but it helps to keep old answers update with current information. I found a much easier and up to date solution:
Cursor.lockState = CursorLockMode.Confined; // keep confined in the game window
Cursor.lockState = CursorLockMode.Locked; // keep confined to center of screen
Cursor.lockState = CursorLockMode.None; // set to default default
↧