Just to give an update, since this topic is out of date but still high on search results, you should use:
`Cursor.lockState = CursorLockMode.Confined;`
This has been available since at least Unity 5.2.
↧