Some things are wrong in your code, or you haven't wrote all your code.
From where your ChangeAlphaValue method is called ? What slider is passed in parameter to it ?
You should add a serialize field of your slider in your script and reference it in the Inspector.
[SerializeField] private Slider m_slider = null;
void Start()
{
...
m_slider.onValueChanged.AddListener(ChangeAlphaOnValue);
}
void OnDestroy()
{
m_slider.onValueChanged.RemoveListener(ChangeAlphaOnValue);
}
public void ChangeAlphaOnValue(float value)
{
ChangeAlpha(currentMat, value);
}
With that code, your ChangeAlphaOnValue is called whenever your slider change value (when you drag it at runtime or set it by code).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…