- Home /
Mouse cursor not locking in the middle of the screen
Whenever I have my mouse cursor locked it never goes to the middle of the screen. In normal view it's a tiny but over the middle and in Fullscreen view it goes all to the left and down. How can I fix this?
void Start(){ Screen.lockCursor = true;
}
void Update () {
if(Input.GetKeyDown(KeyCode.Escape)){
Screen.showCursor = !Screen.showCursor;
Screen.lockCursor = !Screen.lockCursor;
}
}
These commands do strange things in the Editor, and can break. To test them properly, you have to build it and test the build.
You mean I have to make the game and then see if it works? I need this to work good right away is there a possible way to make this happen?
Just do a PC/$$anonymous$$ac build and run it. Or make a web build, upload it, and then run it. Note you can always 'hide' the cursor and then provide your own cursor-like object and control it any way you like.
Will this make the cursor go to the right spot after I tried building it or will it just show when in "built mode"? And how can I use this cursor-like object your talking about? I'm still kinda new in Unity
You don't describe your problem very well, so I'm not sure how to advise. You can make an object follow the mouse position. Lots of posts on this including code for GUI, GUITextures, and 3D objects. The script that follows the mouse, can also 'disable' itself and place the object at the center of the screen. With the mouse not visible, the user does not know that they are not looking at a real cursor. And this should work in the editor.
Answer by IgorAherne · Jul 21, 2013 at 10:12 PM
The thing you would ultimately be trying to achieve is to set the position of the cursor according to the Screen.Width.
Unfortunately it can't be done easily:<
There is a thread on this which can get you going http://answers.unity3d.com/questions/9408/set-cursor-position.html
Answer by Tap2Continue · Oct 18, 2014 at 08:24 PM
I created this JavaScript a little while ago. It's really simple actually.
function Start()
{
Screen.lockCursor = true;
}
if(Input.GetKeyDown("esc"))
{
Screen.lockCursor = false;
}
Your answer
Follow this Question
Related Questions
Keep cursor in the middle of the screen? 1 Answer
Cursor Lockmode only works once? 1 Answer
Cursor bug 0 Answers
Keep Cursor at center and project interactions to cursor position on mobile touch devices (IOS) 0 Answers
Cursor.lockState does not work 2 Answers