Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by CalledToGaming · Apr 26, 2010 at 09:18 PM · mouselooklock-cursormouse-look

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
9
Best Answer

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;
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CalledToGaming · Apr 27, 2010 at 12:32 AM 0
Share

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.

avatar image Prances · Feb 24, 2015 at 09:07 AM 0
Share

Nice, it works even 5 years later.

avatar image
2

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CalledToGaming · Apr 26, 2010 at 11:45 PM 0
Share

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

avatar image e-bonneville · Apr 27, 2010 at 12:09 AM 0
Share

I've updated my answer.

avatar image NocturnalVirus · Jun 27, 2013 at 01:54 AM 1
Share

I am getting BCE0005: $$anonymous$$ identifier: '$$anonymous$$ouseLook'.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

how to detect if a non-moving object exist in a position? 1 Answer

Script to disable MouseLook? 2 Answers

Check if gameobject has script with inheritance 2 Answers

Difficulty Calling Variables from other scrtipts 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges