- Home /
Show and unlock mouse on key press
Hello,
I just started learning javascript and unityscript today, and i tried to make my own script. So, what i want to do: When you press the key (Tab) the mouse will unlock from the center, will be visible and you will be able to move mouse without moving the camera.
My Code(please tell me where i have bugs):
function Start (){
Screen.showCursor = false;
}
function Update () {
if (Input.GetKey (KeyCode.Tab))
Screen.lockCursor = false;
Screen.showCursor = false;
}
else
Screen.lockCursor = true;
Screen.showCursor = true;
}
}
Yes i know in the code i don't have the lock camera function. I don't know how to do that
This script will be use to drag items.
Answer by CodeMasterMike · Jan 28, 2013 at 03:36 PM
You were missing a '}' for your else-statement. You need to be carefull, because if you miss a "little" thing like a '{' or a '}' you can get great troubles :-)
function Start ()
{
Screen.showCursor = false;
}
function Update ()
{
if (Input.GetKey (KeyCode.Tab))
{
Screen.lockCursor = false;
Screen.showCursor = false;
}
else
{
Screen.lockCursor = true;
Screen.showCursor = true;
}
}
Always try to make your code as clear and readable as possible, specially when you are new to programming. You will save a lot of headache and time that way in the future.
Good luck!
Thank you very much ;) now i just need to figure out how to lock the camera
Your answer
![](https://koobas.hobune.stream/wayback/20220613091734im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Cursor Locks/Hides but Will Not Reappear? 1 Answer
What am I doing wrong in this 1 Answer
where should i put this script 2 Answers