Any way at all to center the cursor?

Hi, I have a game object, a flashlight, that I want the player to be able to pick up. I have a crosshair in the center of the screen. The pick up script says that I have to click on the object with the mouse to pick it up, and I thought that would be fine, since I thought that Screen.lockCursor centres the cursor AND hides it. But apparently it doesn’t centre it because when I try to pick up the item, I can never pick it up while directly looking at it!

I tried looking up a way, and I seriously cannot find a working solution, sometimes it would be said it was impossible at the moment!

Is there any way to truly centre the cursor?

Or could some one advise me an alternative to my pick up script?

Pick up script (the relevant part):

function OnMouseDown () {
    gameObject.active = false;
    Destroy(gameObject);
}

This is a good question but unfortunately, I don’t think we will be able to achieve what you want. Control over the location of the mouse cursor is considered a very privileged operation. Imagine a malicious (or just plain broken) application could control the mouse pointer. This would mean that the mouse could simply NOT be moved out of the window rectangle. For many “simple” users of computing, this would be very intrusive. Imagine no way to get to the task bar to “Close” an application. Because of this, access to control the location of the mouse cursor is considered “constrained”.

A second reason is more subtle but still very practical. On my desk, my mouse lives on my mouse pad. When the cursor is centered in the screen, the mouse happens to be in the center of my mouse pad. When I move the mouse to the left of the pad, it is on the left of the screen (and so on). Repositioning the mouse cursor would disassociate the physical location of the mouse on the mouse pad to its logical location on the screen. Again, many users simply aren’t aware that they pick up the mouse and move it themselves … but some are.

You could cast a ray from the camera to the center of the screen and if it hits the flashlight (and the player is close enough) it will be picked up.