Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by AtomicMarine · Jan 12, 2013 at 12:33 PM · guidetectiononguiright click

Detect Right Click on GUI Buttons

Is it possible to easily detect weather the player has left or right clicked an OnGUI function Button.

I Know that placing a simple IF before the button will supply a true false for if it is left clicked, however how does one do this for right clicks.

Thanks guys, Dom

Comment
Add comment · Show 1
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 JmPrsh153 · Apr 13, 2015 at 06:21 PM 0
Share

this method doesnt work anymore..... im using unity 5... not using the new gui but still using the old... i want to detect if im right clicking the gui.button etc :/

2 Replies

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

Answer by MeditatingGamer · Jul 03, 2013 at 09:48 PM

 if(GUI.Button(new rect(0,0,0,0), "Button")) {
     if(Input.GetMouseButtonUp(0)) {
         Debug.Log("left click");
     }
     else if(Input.GetMouseButtonUp(1)) {
         Debug.Log("right click");
     }
                     
 }

I noticed your post, hope your still checking up on it. This is something I tossed together that works for me. And I also hope this helps you and whomever is coming across this problem.

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 Ash-Blue · Jul 13, 2017 at 08:32 AM 0
Share

Looks as of Unity 5.6 this isn't working anymore. @robertbu has the correct answer with using var e = Event.current;.

avatar image
3

Answer by robertbu · Jul 04, 2013 at 01:13 AM

You can look at the Event. Event.button is an int that indicates which button was pressed.

 #pragma strict
 
 function OnGUI() {
     var e = Event.current;
     
     if (e.type == EventType.MouseUp && e.button == 1)
         Debug.Log("Right mouse button lifted");
 }


Comment
Add comment · 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

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

12 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

Related Questions

[Solved] GUI Error? 1 Answer

Ignore Input.GetMouseButtonUp for clicks that were used on GUI elements 2 Answers

Is there a way to set a GUI.matrix that will be used by all OnGui() functions? 1 Answer

Fill a circle by values with onGUI 0 Answers

How to display a set of guiText OnGUI 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