x


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!

more ▼

asked Apr 26 '10 at 09:18 PM

CalledToGaming gravatar image

CalledToGaming
190 21 24 30

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
more ▼

answered Apr 27 '10 at 12:16 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

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 instead of another one I was using it seemed to work. Whatever works I guess, right?

Thanks again.

Apr 27 '10 at 12:32 AM CalledToGaming
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 26 '10 at 11:31 PM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

I thought the same thing, but I can't figure it out on a CS script. I'm used to JS

Apr 26 '10 at 11:45 PM CalledToGaming

I've updated my answer.

Apr 27 '10 at 12:09 AM e.bonneville
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5086
x3334
x162
x25
x21

asked: Apr 26 '10 at 09:18 PM

Seen: 4725 times

Last Updated: Apr 26 '10 at 09:18 PM