Hey there! I'm trying to create three sliders which sum to 100% (or 1.0, doesn't matter). So for example, if the sliders are 0.40, 0.40, 0.20, and the user changes the first slider to 0.85, the other two sliders should become 0.1 and 0.05 (proportionally the same). My current problem is that I'm using onValueChanged to change the values, which causes infinite recursion. What's a better way to flow the logic?
#Preventing Infinite Recursion on Sliders
1 messages · Page 1 of 1 (latest)
If you want to use OnValueChanged, then you need to cache which slider is the active one and check that only that slider can do something when changed.
There are functions for dragging and such you could potentially use to know which one is active. https://docs.unity3d.com/2018.2/Documentation/ScriptReference/UI.Slider.html
But really, it would be easier if you just went the array method. Even for prototyping.
Use this to set the value in the code instead of .value = https://docs.unity3d.com/Packages/com.unity.ugui@1.0/api/UnityEngine.UI.Slider.html#UnityEngine_UI_Slider_SetValueWithoutNotify_System_Single_
Thanks!!!
How would arrays make this easier?
You mean just for making changes uniformly?
You can just directly modify them, and you could easily cache the index of the one being controlled.