In unity, the mouse is locked in the center of the screen and the mouse cursor is hidden.

Cursor.lockState = CursorLockMode.Locked;

  • Cursor.lockState is a static property used to set the mouse lock state. By assigning CursorLockMode.Locked to Cursor.lockState, the mouse can be locked in the center of the screen. When the mouse is locked, the mouse cursor is hidden and remains centered on the screen no matter how the player moves the mouse. This is common in games that require precise positioning and manipulation by the player, such as first-person shooters. Note that once the mouse is locked, the player needs to press a specific key (usually the Escape key) to unlock the mouse, making the cursor visible and freely moveable again. The part of unlocking the mouse is not shown in the code, but it is usually necessary to add the logic to unlock the mouse at the appropriate time.

In this way, we can apply it in some games that require players to accurately position and operate.



Supongo que te gusta

Origin blog.csdn.net/zzexcellent27/article/details/134842248
Recomendado
Clasificación