How to lock the mouse cursor position in Unity and hide it

introduce

How to lock the mouse cursor position in Unity and hide it? Common fps games require such settings


method

The way to hide the mouse cursor in Unity is to use the Cursor.visible property and Cursor.lockState property.

To hide the mouse cursor, set the Cursor.visible property to false and Cursor.lockState to CursorLockMode.Locked, which will lock the mouse in the center of the screen and hide the cursor.

Here is a simple example code that demonstrates how to hide the mouse cursor in Unity:

void Start()
{
    
    
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
}


Guess you like

Origin blog.csdn.net/qq_20179331/article/details/130462443