- Home /
Lock cursor help
I have tried to make a script that locks the cursor in the center of the screen but it doesn't work. Here's my code:
function Start () {
Screen.lockCursor = true;
}
All help would be appreciated, thanks! By the way my preffered language is javascript.
Answer by Josh1231 · Jul 20, 2013 at 08:15 AM
Vector3 mousePos = Input.mousePosition;
mousePos.x = Screen.width / 2;
mousePos.y = Screen.height / 2;
Input.mousePosition = mousePos;
puts it in the center.
Answer by Grizzly · Aug 09, 2014 at 12:27 AM
jimmy_games5634 , Your script is ok ,it does what it should ,you can test in the build version ,however in Unity editor it wont work ,it will just hide the mouse but it will not center it in the middle of the screen.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110458im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
What am I doing wrong in this 1 Answer
Scripts stop working in Maximize On View and testing on Android 0 Answers
Having problems with my timer 1 Answer
(C#)How To Disable Gravity From Script? 4 Answers