- Home /
Setting initial value of slider automatically
I have UI Slider and under OnValueChanged, I picked a camera's orthographic size. So when the slider value is changed, it changes camera's size. But the slider's initial value stays whatever it is set in the editor. I want the initial value of the slider to be set to the camera's size. How can I use the variable I picked in editor under OnValueChanged to set the starting value of the slider? I am looking for a more generic solution because I will have multiple sliders, each will pick a different variable to change. O do I really have to write a script for each occasion? I want the chosen variable (as in the screenshot) to be used to set the initial value.
Answer by Llama_w_2Ls · Jan 27, 2021 at 02:49 PM
How about:
public Slider[] sliders;
public float[] values;
void Start()
{
for (int i = 0; i < sliders.length; i++;)
{
sliders[i].value = values[i];
}
}
This way, you only need one script, to manage the start value of all your sliders. @metinevren
Your answer
Follow this Question
Related Questions
UI slider "End slide" event 3 Answers
UI Toolkit - prevent click through visual element 1 Answer
Dynamic slider size with the new UI 2 Answers
left end of slider fill flattening the more i move the value down 0 Answers
Why hip will move upward and downward automatically when start to drag slider at x,y and z axis? 0 Answers