0

I'm working on a mouse manager script. I want to be able to left click on the instantiated text object and have it do one thing, and do something else when right clicked. Trouble is you can't send a parameter to an event trigger OnCLick and to send the base event data doesn't give you which button was clicked. I can't simply use Update because I only want them to right click on the text object not anywhere, especially since I want the right click to delete the object. I've looked and looked, one would think this were a common enough problem to find a solution, but alas.

I already have an OnEnter and OnExit, which changes the colors of the text. Anyone have a solution? Thanks!

asked Jun 26, 2017 at 16:16

1 Answer 1

1

In case anyone else has been pulling out their hair over this kind of issue. I finally found a solution and it works very well. So I will share it.

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class RightClick : MonoBehaviour, IPointerClickHandler
{
 public UnityEvent leftClick;
 public UnityEvent middleClick;
 public UnityEvent rightClick;
 public void OnPointerClick(PointerEventData eventData)
{
 if (eventData.button == PointerEventData.InputButton.Left)
 leftClick.Invoke ();
 else if (eventData.button == PointerEventData.InputButton.Middle)
 middleClick.Invoke ();
 else if (eventData.button == PointerEventData.InputButton.Right)
 rightClick.Invoke ();
}

}

answered Aug 10, 2017 at 19:30
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.