uGUI - How to listen for Slider-Handle release?

Hey all,

I have a volume slider and want to play a sound after the slider handle has been released (OnEndDrag).
As suggested here, I’m using the IEndDragHandler interface. However the OnEndDrag and OnBeginDrag methods never get called. What am I doing wrong?

I’m using it like so:

public class UISimpleSlider: IEndDragHandler, IBeginDragHandler
    [SerializeField] private Slider slider;

    //... some slider init and refresh code goes here

    private bool isBeingDragged = false;
    public bool IsBeingDragged()
        return isBeingDragged;

    public void OnEndDrag(PointerEventData data)
        Debug.Log("drag end");
        isBeingDragged = false;

    public void OnBeginDrag(PointerEventData data)
        Debug.Log("drag start");

        isBeingDragged = true;

At first I thought about working with onValueChanged, however this would fire the sound every time the value changes and not only after the handle has been realeased.

1 Like

Solved it by using the inspector. You can add the event trigger component to your slider gameobject and set the BeginDrag and EndDrag events to call your specific methods. See screenshot below: