- Home /
Question by
MerlinsMaster · Jul 05, 2016 at 05:59 AM ·
slidergetmousebuttondown
How to make a slider value change by clicking on it
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?
Comment
Answer by Last_Imba · Apr 17, 2020 at 10:02 AM
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;
}
}
}
Your answer
Follow this Question
Related Questions
Slider to modify a countdown time in another scene 0 Answers
Reverse slider min/max values 0 Answers
How do I nest or use if/and correctly? 1 Answer
how to create GUI slide effect ?? 1 Answer