- Home /
Make a Cursor Disappear?
How would I write a script to make a cursor disappear when I press a key on my keyboard and then reappear when I press that key again?
Answer by Jean-Fabre · Nov 12, 2010 at 06:41 AM
Hi,
Try something like this ( javascript )
function Update () {
if ( Input.GetKeyDown ("space") ){
Screen.showCursor = !Screen.showCursor;
}
}
Hope it helps,
Jean
excuse me which gameobject would i put the script in?
Yo could put this on any game object in any scene and it would work (in that scene of course).
I put this in a empty(gameobject>>>Create Empty) and it didn't work for me BTW i changed the space to a c does it have to be c
Thanks for responding so quickly :)
This will work, except that Darkforce needs to ins$$anonymous$$d of putting get button, you need get key. You don't need to do this, but you can't just change "space" to "c" and expect it to work. Try this ->
function Update () {
if ( Input.Get$$anonymous$$eyDown ("c") ){
Screen.showCursor = !Screen.showCursor;
}
}
//Or go into Edit->Proj Settings->Input and add the button i.e. CHEAT and put the positive //key as "c".
//Then, insert this coding into whatever you want, but I would suggest something like your //character or similar.
function Update () {
if ( Input.GetButtonDown ("Cheat") ){
Screen.showCursor = !Screen.showCursor;
}
}//It can be named whatever you want, and have whatever key you want.