Question by
spinnerbox · Dec 15, 2015 at 01:48 PM ·
unity 5slideruser interfacerange
Make 2 sliders dependent on each other
I want to make 2 UI sliders dependent on each other. Both of them represent a range of whole numbers. The first one would give the minimum of the range and the second would give the maximum.
The problem is, the min slider must not go over a value of the value of the max slider - 2. And the value of the max slider must not fall bellow the value of the min slider + 2.
Yes there is OnValueChanged event but how can I stop the slider from moving once it reaches, say maxSlider.value + 2?
There is option to make the slider disabled but that whould be like turning it off completelly.
Comment
Best Answer
Answer by spinnerbox · Dec 15, 2015 at 02:11 PM
Found a solution. Somebody might have use of it:
public void MinSliderValueChanged ()
{
minSlider.maxValue = maxSlider.value - 2;
maxSlider.minValue = minSlider.value;
MaxTxt.text = maxSlider.value.ToString();
MinTxt.text = minSlider.value.ToString();
}
public void MaxSliderValueChanged ()
{
minSlider.maxValue = maxSlider.value;
maxSlider.minValue = minSlider.value + 2;
MinTxt.text = minSlider.value.ToString();
MaxTxt.text = maxSlider.value.ToString();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612052723im_/https://answers.unity.com/themes/thub/images/avi.jpg)