- Home /
How do i disable mouselook when a button is pressed?
Using the MouseLook script in the standard assets project, How would I disable the script when a button is pressed?
Here's the set up: I have a script that Hides the Cursor (for fps sake) unless you press the "Left Alt" button. When you press Left Alt, the cursor shows back up. That works fine. However, I'd like the MouseLook Script to be disabled when I press the Left Alt Button and then Re Enabled when I release the Left Alt Button.
By Doing this, I could adjust options, or select objects on the screen without the camera continuing to rotate.
Thanks for any help!
Answer by Eric5h5 · Apr 27, 2010 at 12:16 AM
Use GetComponent to get a reference to the script, and set enabled to false or true as necessary. Use GetButton rather than hard-coding keys, so it can be changed by the user easily (in a stand-alone anyway).
if (Input.GetButtonDown("ShowMenu"))
GetComponent(MouseLook).enabled = false;
else if (Input.GetButtonUp("ShowMenu"))
GetComponent(MouseLook).enabled = true;
Thanks much, I had this exact same script already put in and it wasn't working. But when I re typed it out in it's own script ins$$anonymous$$d of another one I was using it seemed to work. Whatever works I guess, right?
Thanks again.
Answer by e-bonneville · Apr 26, 2010 at 11:31 PM
Use a boolean variable that gets set to true on left alt down, and set to false on left alt up. Then, in your mouselook script, add an if statement surrounding the mouselook part of the script. If it's not true (alt isn't held down) then you can rotate. if it is true (alt is held down) than it can't move.
EDIT: Here's a JS mouselook.
I thought the same thing, but I can't figure it out on a CS script. I'm used to JS
I am getting BCE0005: $$anonymous$$ identifier: '$$anonymous$$ouseLook'.