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.

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 :slight_smile:

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!