UI4.6 Slider Scripting: a generic way of changing variable value using slider ?

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

The ui slider has a OnValueChanged event that you can just set from its inspector. You can simply make sure your script has a public method that matches the signature for that event and than assign the new method to that callback in the inspector. The event will send over some data including the value of the slider in the callback arguments.

I have trouble witting a method that match signature for that event and can’t be used to set any variables.
I use this and i set it fro the inspector like u said (if i understood).

public void OnhSliderChanged(float val) {
someScript.someValue = val;
}

This will work for a specific variable.
If i want to make it work for a non specific variable i think i need something like that.

public void OnhSliderChanged(float val,ref float variableToChange) {
variableToChange = val;
}

But it won’t match signature of OnValueChanged.