- Home /
Move Slider-value to middle value when released
Hello,
I am trying to move my player with a slider on its x-axis.
The player-movement speed is determined how far the value is away from 0, the middle value.
However, when the Handle-slider is released, it should turn back to 0, else it will keep adding x-movement to the player.
It can be compared to "Input.GetAxis("Horizontal")" as it has the range from -1 to 1 and goes back to 0 if nothing is pressed.
Thanks in advance.
Answer by Rostam24 · Sep 26, 2015 at 10:47 PM
Does the player move the slider using a mouse or touch? Assuming you don't want anything too fancy (just something that works), you could simply use input.getmousebuttonup(0) inside of update, and then set the slider to the middle whenever that happens :)
Primary I want this for android, but the mouse/finger should then be over the handle slide area.
I have written some code that should do what I want, but there is an error:
horizontal = slider.value;
if(!slider.OnDrag(EventSystems.PointerEventData.dragging)){
slider.value = 0;
}
An instance of type 'UnityEngine.EventSystems.PointerEventData' is required to access non static member 'dragging'.