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:
)
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.
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");
}
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.
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.