Hi,
I’m trying to figure out a way to build a generic function to Update a script value using Sliders.
How i actually use my sliders to change other script variable, it’s working but i need to create a function of each of my sliders and i have a lot of slider…
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Remember to include this
public class Gui : MonoBehaviour {
public Slider hSlider;
void OnSliderChanged() {
someScript.someValue = hSlider.value;
}
}
//Or
public void OnhSliderChanged(float val) {
someScript.someValue = val;
}
So i’m looking for a function which Instantiate a new slider linked to some variable.
To sum up:
i have a script with :
public static float variable1;
public static float variable2;
…
And in an other script i want to create sliders or only linked pre created sliders to those variable without writing a functions for each variable.
I know how to instantiate via script Slider but when i need to AddListener i can’t figure out how to write a generic function which will do work like OnSliderChanged for a given variable, cause OnValueChange only take 0 or a float argument (so i can’t pass a ref float ).
I’m a bit lost, it’s seems like a classic feature but i can’t find any answer to my issue.
I’m sorry if my question is unclear i redraft it several times.
Please excuse my poor English