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 Solist · Feb 09, 2017 at 07:21 AM · eventsystemonclicklistenerright click

How do I attach Right Click to an EventSystem listener?

I'm trying to attach both a left click function call and a right click function call to an EventSystem listener. I seem to be successful with the left click but not the right click.

I'm currently trying to run a variable (int) that is stored from Update when you left or right click, but the EventSystem doesn't even bother registering right clicks, so the listener is never run for right clicks, is there some way to force the EventSystem to pick up on right clicks?

I was hoping to avoid running update every frame just to check for a right click as I only want to check for this right click when the UI is open (Right click is used for other things related to game play while the UI is closed).

 public int currentMouseInput = -1;
 
 public Button tempButton = new Button();
 
 
 void Start() {
     tempButton.onClick.AddListener(() =>
     {
         if (currentMouseInput == 0)
         {
             print("Left Click Working");
         }
         else if (currentMouseInput == 1)
         {
             print("Right Click Working");
         }
     });
 }
 
 void Update() {
     if (Input.GetMouseButtonDown(0)) 
     {
         currentMouseInput = 0;
     }
     else if (Input.GetMouseButtonDown(1))
     {
         currentMouseInput = 1;
     }
 }

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
0
Best Answer

Answer by HarshadK · Feb 09, 2017 at 11:59 AM

AFAIK there is no default onClick event to receive right click on a button. The onClick is for left click only. But you can create one using OnPointerDown from IPointerDownHandler and OnPointerUp from IPointerUpHandler interfaces.

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 neighborlee · Sep 26, 2019 at 08:11 PM 0
Share

Sorry old, but appicable tomy concern I think:HOw do I get rightclik play in unity,like ue4 has ? Not a highly skilled programmer , hence my question--does THIS thread help to that end ?

ty

avatar image Mouton neighborlee · Sep 26, 2019 at 09:04 PM 0
Share

No, your question is not related to this one.


If you try to achieve a click on a GameObject, look at this question: https://answers.unity.com/questions/373818/how-to-detect-mouse-click-on-a-gameobject.html

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

6 People are following this question.

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

Related Questions

onClick stops working after a while 0 Answers

Weird behaviour when trying to dynamically create buttons 0 Answers

ArgumentOutOfRangeException 1 Answer

button.onClick.AddListener(method); NOT Working 1 Answer

AddListener() Javascript 2 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