Make the cursor stay in the middle of the screen

How do i lock the cursor to be always in the middle?

I’ve spent hours,

  • I’ve tried Raycasts, yes it works but some objects of mine has scripts(multiple) that has IPointer which is not detected.
  • +Locking the cursor or Locking and unlocking in Update doesn’t work like most suggested according to years before posts

The Cursor in the middle is, I assume a cross-hair icon? If so, don’t make that the cursor icon but just a fixture in your UI that’s always in the middle.

Then hide the actual cursor when ever the game gets the focus, by registering to the Application.focusChanged event and in your callback receiver, make the cursor invisible and ideally also lock it to the center of the screen (which does set it as invisible). See here for code examples.

Locking the cursor means the position won’t change, so if your scripts rely on that to turn the camera, you need to switch them to react to the delta movement of the cursor instead.

I don’t get what you mean since the cursor is technically always in the middle.

Have you tried:

Cursor.visible = true;