I want to have a slider that, when you left-click on it, adds 1 to the slider value, and when you right-click on it, subtracts 1 from the slider value. I tried attaching a script to the slider with a GetMouseButtonDown input on it, but the slider doesn’t respond to the mouse clicks the way a normal game object does.
Does anyone have any suggestions for how I can do what I’ve described above?
Four years later:
public class ToggleSliderByClick : MonoBehaviour, IPointerDownHandler {
private Slider _slider;
private void Start() {
_slider = GetComponent<Slider>();
}
public void OnPointerDown(PointerEventData eventData) {
switch (eventData.button) {
case PointerEventData.InputButton.Left:
DoActionLeftCLick();
break;
case PointerEventData.InputButton.Right:
DoActionRightClick();
break;
case PointerEventData.InputButton.Middle:
DoActionMiddleClick();
break;
}
}
}