- Home /
disable script when i press escape??
hey, i have this java script that locks the mouse for my FPS
function Update () {
Screen.showCursor = false;
Screen.lockCursor = true;
Screen.lockCursor = false;
}
if(Input.GetKeyDown("escape")
{
paused = !paused ;
if(paused) //Do Stuff When Paused
{
Screen.showCursor = true;
}
else // Do stuff when unpaused
{
Screen.showCursor = false;
}
}
}
it shows error saying, Assets/_Scripts/MouseLOCK.js(10,3): BCE0044: expecting ), found '{'.
i need it so when i press escape it turns off the lock script so that way i can navagate the menu and when i press escape again it turns lock back on.
thanks guys
First please format your code - Check out the unity tutorial.
var paused : boolean = false;
function Update ()
{
if(Input.Get$$anonymous$$eyDown("escape")
{
paused = !paused ;
if(paused) //Do Stuff When Paused
{
Screen.showCursor = true;
}
else // Do stuff when unpaused
{
Screen.showCursor = false;
}
}
}
function Update () {
Screen.showCursor = false;
Screen.lockCursor = true;
Screen.lockCursor = false;
}
var paused : boolean = false;
function Update ()
{
if(Input.Get$$anonymous$$eyDown("escape")
{
paused = !paused ;
if(paused) //Do Stuff When Paused
{
Screen.showCursor = true;
}
else // Do stuff when unpaused
{
Screen.showCursor = false;
}
}
}
i tried this but it gives me errors... the script locks the mouse but need it to unlock the mouse when i press escape then re lock it once i press it again...:(
Answer by Ryanvanpolen · Jan 22, 2014 at 10:50 AM
you use no boolean... (R6)
if(input.GetKeyDown("escape")) {
//you say paused = !paused
paused = true; //if you tap escape, than is pause true
if(paused) {
//do some stuff...
}
//you don't need an else, but you can do it if you like to
}
Maybe this works better...
succes
no this won't since pause is always true. He wants to press escape to set on and off.
Answer by hannm · Jan 23, 2014 at 10:44 PM
i changed it to
function Update () {
Screen.showCursor = false;
Screen.lockCursor = true;
Screen.lockCursor = false;
}
if(Input.GetKeyDown("escape")
{
paused = !paused ;
if(paused) //Do Stuff When Paused
{
Screen.showCursor = true;
}
else // Do stuff when unpaused
{
Screen.showCursor = false;
}
}
}
but it gave me error saying, Assets/_Scripts/MouseLOCK.js(10,3): BCE0044: expecting ), found '{'.
can anyone re write it for me?? i thought i fixed it but nope :(
thanks
Your answer
Follow this Question
Related Questions
Cant unlock cursor with FPS prefab 2 Answers
Cursor lock not working after alt tab 2 Answers
Lock mouse position with a Rect, possible? 1 Answer
turn off script with a key.. 1 Answer