Is there a way to check if a dropdown has been clicked?

In the same way that a button has the “onClick” callback, I was wondering if there’s its equivalent for dropdowns.

I want to play an audio clip when the dropdown opens. It successfully plays a one shot whenever one chooses an option from the list (with the “onValueChanged” callback), but I don’t seem to find a way to do it when clicking on the dropdown.

In the documentation, I saw it’s got a “OnPointerClick”, but I couldn’t figure out how to use it (it says:
8716977--1178409--upload_2023-1-9_16-59-55.png
)

On this thread, this person managed to achieve kind of the same thing (by detecting when the Dropdown List is created and destroyed), but it feels a little hacky and I’d like to avoid it if possible.

Thank you.

8716977--1178409--upload_2023-1-9_16-59-55.png
8716977--1178409--upload_2023-1-9_16-59-55.png

Unless I miss my guess Add IPointClickHandler to your class and then implement that interface

public class TestManager : MonoBehaviour, IPointerClickHandler

public void OnPointerClick(PointerEventData pointerEventData)
    {
        Debug.Log("OnPointerClick");
    }
1 Like

I was trying these options:

_dropdown.OnPointerClick.AddListener(PlaySound); // try 1
_dropdown.OnPointerClick.AddListener(delegate // try 2
        {
            PlaySound();
        });

_dropdown.OnPointerClick.AddListener(() => { PlaySound();}); // try 3

_dropdown.OnPointerClick += PlaySound; // try 4

But none of these works even with the interface implemented.

I guess I have to create this kind of script and attach it to the dropdown, and then send the event via c# delegates, for instance. It seems a little cumbersome not having a method/callback like “onClick” for the dropdown.

Thanks

It is subtle but you would have seen OnPointerClick in the list of properties associated with the dropdown. That one along with a few others are implemented as virtual methods so rather than add a handler you implement the method.