- Home /
How to lock the cursor to the center of the screen.
My code so far:
void Update(){
Cursor.lockstate = lockmode.lock ;
cursor.visible = true;
}
Comment
^ should work? what's the problem? Have you tried building your game and running it? And not just from the editor.
Thank you , after i built and run it it worked properly.
Answer by JonKach · Aug 30, 2020 at 01:23 PM
I used this and it worked perfectly
Cursor.lockstate = CursorLockMode.Locked;
This should lock your cursor, make sure to put it in the Start Function.
When i ran my game in the Unity editor there there was a prob with it moving to a random place.But now after building and running it, it works perfectly.......Yet thanks for the reply :-).
It says "error CS0117: 'Cursor' does not contain a definition for 'lockstate'"
Cursor.lockState = CursorLockMode.Locked is what @JonKach meant
Your answer