In Unity, you can lock the state of the cursor while in play mode, effectively turning the cursor invisible and constraining it to the center of the screen so that you don't accidentally click on anything while playing, which can happen often and is very problematic. Being able to lock the cursor is very helpful for both playing and testing games. These are the two lines of code that do the trick, tough some additional scripting may be required:
lockMode = CursorLockMode.Locked;
Cursor.lockState = lockMode;
Additional resources on cursor locking in Unity and other cursor modes:
https://docs.unity3d.com/ScriptReference/CursorLockMode.html
https://docs.unity3d.com/ScriptReference/Cursor-visible.html
https://forum.unity.com/threads/disable-mouse-cursor-in-windows-during-play-mode.387416/
No comments:
Post a Comment