• 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
0
Question by ks13 · Dec 16, 2011 at 12:54 PM · bugonmousedownbehaviour

OnMouseDown() intended behaviour

Hello i'm trying to use OnMouseDown to make possible to interact with objects. So far it's no real problem using it. But then i discovered one little thing that might force me to change all my script :
When i click with mouse left button it works fine, but doesn't rect with the other mouse buttons. Is this an intended behaviour or a bug?

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

1 Reply

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

Answer by BiG · Dec 16, 2011 at 01:11 PM

Yep, OnMouseDown() works only with left button. Checking for the pressure of a generic mouse button requires the implementation of an "overriding technique", that uses OnMouseOver(). A thing like this:

function OnMouseOver()
{
    if (Input.GetMouseButtonDown(1)) //right button pressed
    {
        // OK, here you perform the action associated with right button
    }
}

However, it seems to me that you have to perform the same action, independently from the button pressed: in this case, the script above is the same, just use a single if condition that includes all the desired buttons.

Comment
Add comment · Show 1 · 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 ks13 · Dec 16, 2011 at 01:46 PM 1
Share

Well, i actually don't use those directly, ins$$anonymous$$d i use a bool to launch the calculations in OnGUI, that way i can use
Event.current.button
or, if it doesn't matter which mouse button :
if (Event.current.type == EvenType.$$anonymous$$ouseDown)
but thanks for the suggestion, till now i was searching for a solution somewhere far away from this simple one.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnMouseDown() won't work unless gameObject's 2DBox Collider - ‘Is Trigger’ is toggled on/off mid-game in editor. 0 Answers

Does OnMouseUp() require OnMouseDown() to be triggered first? 1 Answer

"the process can not access the file because it is being used by another program" 3 Answers

Pixelartifacts on edges when activating Antialiasing... 4 Answers

ExternalEval not working on Mac? 0 Answers


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