- Home /
How i restrict slider movement to one direction?
Im using a horizontal slider to change a value.Say the start point is 'A' and the end point is 'B'.I want the slider to only move from A to B and restrict movement from B to A.
Any ideas on how i could get that to work?
Answer by Jesse Anders · Jan 24, 2011 at 07:35 AM
I'd probably just do it in OnGUI(), e.g. (untested):
float newValue = GUI.HorizontalSlider(..., currentValue, ...);
currentValue = Mathf.Max(currentValue, newValue);
Answer by Thom Denick · Jan 24, 2011 at 07:31 AM
Poll your slider in the Update() Method.
If the value of the slider goes below the current slider value:
if(newSliderValue < currentSliderValue) {
newSliderValue = currentSliderValue;
} else {
currentSliderValue = newSliderValue;
}
Set it to the current value instead of the new one.
Your answer
Follow this Question
Related Questions
GUI Sliders in the same script. Question (Js.) 1 Answer
Curving an Horizontal Slider 2 Answers
HorizontalSlider? 1 Answer
How to make a Horizontal Slider slide between resolutions? 3 Answers
Horizontal Slider issue 0 Answers