Seriously, no support for right click for OnPointerClick?

What the heck? Why is there no support for right click on the OnPointerClick? It just ignores all right clicks and only accepts left clicks. Why would you leave out something so simple, and especially considering gamepads could have multiple buttons that you might want to interact with it. For instance, an item I want to right click to do one thing, and left click to do another. Or even, on a gamepad have O do one thing and X do another for the same item.

I can't use Input.GetMouseButton because OnPointerClick is called after the mouse button has already been released, plus OnPointerClick is never called for right click!!!

3 Likes

Huh. Would you believe, I don't think anyone ever brought this up during the beta?

It looks like it might be possible to support this by adding a custom InputModule, but not very cleanly.

We will fix this ASAP, can you please log a bug so we can track it?

1 Like

Hi guys,

not sure if i have overlooked something. But i started like 2 weeks ago with a new game, initially used NGUI and now happily switched to the 4.6 UI which is pretty damn good.

Until today where i stumbled upon states of a button. How do i check if a button is KEPT being pressed? I want an event that either gives me up/down or a state that i can check for in Update(). Because i have a FastForward Button in the game and it is supposed to run as long as the user holds it. Did i miss something or is this just not possible right now?

Please also let me know where i can create the ticket if this is a bug!

br,
Marcus

Add an EventTrigger component and check for PointerDown. Set a flag for the state there. Remove the state in a PointerUp event method. How you want to apply the functionality of it being pressed depends on your implementation, of course :)

Okay, I filed a bug report using the Unity Bug Reporter on my Mac. I would also just like to note that this problem also applies to OnPointerUp and OnPointerDown as well not detecting anything but the primary button such as left click. They also ignore any other button on the mouse or gamepad.

Whats the status on this, has this changed?

The PointerEventData passed to the different methods now has an attribute for the button clicked, pointerId. It's -1 for the left mouse button, -2 for right and so on.

1 Like

Thanks Orb, is that functionality available for the UI Button?

Yep, as long as you write a custom script with the event method.

I apologize if I'm asking too much of you, when you say write a custom script with the event method. do you mean doing my own raycast on a rightclick and making that determination of what was hit. Or modifying the functionality of the UI Button so that it reacts in a similar manner to a right as well as left click (animation or colors when clicked, calls methods you may have specified in Onclick() in the inspector...etc).

If it's the later, I am not quite sure how to go about that, would you be able to point me in the right direction?

Edit: Oh, I'm running 4.6.0, I might want to try updating to 4.6.3 first.

Nothing so complicated :)

Example:

using UnityEngine;
using UnityEngine.EventSystems;

public class Clicky : MonoBehaviour, IPointerUpHandler
{
    public void OnPointerUp(PointerEventData data)
    {
        Debug.Log("Button "+data.pointerId+" up");
    }
}

Add IPointerDownHandler and OnPointerDown, or IPointerClickHandler and OnPointerClick as needed. Check that data.pointerId to select which button is pushed (or which finger, in the case of touch).

Oh I see, it appears to automatically adds it in for you. I was trying to find out how to add my methods to the invocation list of w/e delegate unity has behind the scenes for the longest time. I also had to update to 4.6.3, which seems to have changed a few things.

I don't think the triggers in the editor GUI have been updated to send to different routes based on which button you press. And yes, the GUI still seems like a beta :)

This still isn't fixed. It works with OnDrag, and OnBeginDrag, but not OnPointerClick.

What version of Unity are you using, because it works just fine for me.

    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left)
        {

This is the start of my method so I limit the response to left clicks only.

3 Likes

Hah funny, I was looking for something exactly like that, I don't know how I missed it. I ended up using OnpointerDown, but this is much better. How embarrassing.