Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
0
Question by jake_card · Sep 28, 2017 at 07:45 PM · mouseclickonmousedownonmouseoverright click

OnMouseDown for right mouse click without being hacky?

Hi Unity people!

I'm building a 2D puzzle game with GameObjects that can be clicked on. My GameObjects have a script with the OnMouseDown method implemented to handle left-clicking. However, I also want to handle right-clicking, which doesn't trigger OnMouseDown.

I've seen some suggestions that look like the following:

void OnMouseOver() {
    if (Input.GetMouseButtonDown(1)) {
        Debug.Log("Right click on this object");
    }
}

If this is still the best solution in Unity 2017, I can live with it, but all the suggestions I saw were really old (the newest was in 2013), so I'm hoping there's something cleaner available now that I've missed. Anyone got anything?

Comment
Add comment · Show 2
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 FortisVenaliter · Sep 28, 2017 at 07:57 PM 0
Share

Not that I'm aware of... I actually only use queries from the Input class for this very reason. It's typically easier to check for a mouse click then raycast to get the selected object.

avatar image $$anonymous$$ · Sep 28, 2017 at 08:13 PM 0
Share

As far as I know that's still the best solution.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by elenzil · Sep 28, 2017 at 10:15 PM

Use UGUI's EventTrigger.

override OnPointerDown(), which gives you a PointerEvent, which contains an InputButton member "button", which tells you left/right/middle.

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 jake_card · Sep 28, 2017 at 10:18 PM 0
Share

Does this apply to GameObjects? I might be missing something, but it looks like this is just for GUI stuff.

avatar image elenzil jake_card · Sep 29, 2017 at 09:12 PM 0
Share

this is just for GUI stuff

that's true. but maybe you could stick a GUI element over/under the whole scene and when you catch a R$$anonymous$$B click you could do a raycast.

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

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I call OnMouseDown() from an outside script? 1 Answer

How to make object clickable when user enter collider ? 0 Answers

RaycastHit only way to do OnMouse events for colliders in Mobile? 0 Answers

OnMouseDown for Right Mouse 2 Answers

How Do You Exit A Game 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