- Home /
setting the mouse position
I have a game where I want to be able to 'lock' the mouse in a certain position (or within the window), and cannot find any related methods in the documentation, and the Input.mousePosition variable is read only, so I can't set it from that.
How would I go about setting the position of the mouse?
As DaveA said, I want to lock the cursor on the screen. I do not want to replace the cursor with a texture, at least at this point.
I just want to bound it so it never leaves the screen when the user is in 'fly' mode.
I can modify the 'Flight$$anonymous$$otor' I made to use mouse deltas, and lock it in the center.
Thanks for the quick responses, will check back later to see if someone has more input.
Answer by DaveA · Mar 19, 2011 at 08:14 PM
I don't know if this will help http://unity3d.com/support/documentation/ScriptReference/Screen-lockCursor.html
but I think you want to set the mouse pointer or mouse cursor (depending on what they like to call it). To set the pointer to a specific place, you may need a system API. Google 'mouse pointer csharp msdn'
Answer by Eric5h5 · Mar 19, 2011 at 08:36 PM
There's no direct way to do it in Unity, but you can disable the system pointer and use a software pointer using a GUITexture or whatever (see here for one way to do it), then you can do what you like with that.
How would you get a software pointer to work with the new Unity 4.6 GUI?