- Home /
How do I keep the mouse in center of screen
Hey guys I have been away for a bit but now I am back and wondering How can I keep the mouse courser in the center of the screen?
I have written a script but can't get it to work?
function Start(){
var mousePos = Input.mousePosition;
mousePos.x -= Screen.width/2;
mousePos.y -= Screen.height/2;
}
I haven't really made a script like this as never needed to so all the help would be great full :D
Thanks -Izzy
Answer by Eric5h5 · Sep 04, 2012 at 06:08 PM
Screen.lockCursor = true;
Other than that you can't programmatically set the mouse position; it's read-only.
Just get rid of the mousePos stuff; it's not doing anything. As I said, the mouse position is read-only.
Thanks mate for all your help :D
function Start(){ Screen.lockCursor = true; }
But how do i keep the mouse in the center, this function just puts in in the place it is
I thought : Screen.lockCursor = true; Hid the mouse pointer completely(well until you press escape)??? Sure I used something different to leave it showing but locked to the center...
escape is for quitting the game view to interact with the other unity main windows in terms if your mouse is locked.
well... you can set the position... BUT that you will need to do it for every single Operation system because it is using a library ("using namespaceOfTheDll;") from windows, there is the link to it:
https://answers.unity.com/questions/9408/set-cursor-position.html
Answer by Unshackled · Jun 26, 2019 at 08:49 PM
Cursor.lockState = CursorLockMode.Locked; or Cursor.lockState = CursorLockMode.None;
Don't forget to combine with
Cursor.visible = true; // or false
if it's what you need