You never actually called the function:
public void GoodSlider(float value)
So just add the line to update and it should work:
void Update()
{
GoodSlider(this.GetComponent<Slider>().value); //Add this
images = gameObject.GetComponentsInChildren<Image>();
foreach (Image image in images)
{
if (Goodvalue >= 0f && Goodvalue <= 14f)
{
image.color = Colors[0];
}
if (Goodvalue >= 15f && Goodvalue <= 34f)
{
image.color = Colors[1];
}
if (Goodvalue >= 35f && Goodvalue <= 63f)
{
image.color = Colors[2];
}
if (Goodvalue >= 64f && Goodvalue <= 100f)
{
image.color = Colors[3];
}
}
}
Side note (untested) : Why don’t you just make your slider go from 0 to 3 for each of the colours? (You can even tick [Whole Numbers] to snap to those numbers) because then you can just:
image.color = Colors[(int)this.GetComponent<Slider>().value];
or
image.color = Colors[(int)Goodvalue];
Instead of the ifs…
An even more efficient way would be to create a ChangeColor method and call it on the sliders OnValueChanged method:
public void changeColor()
{
GoodSlider(this.GetComponent<Slider>().value);
images = gameObject.GetComponentsInChildren<Image>();
foreach (Image image in images)
{
image.color = Colors[(int)Goodvalue];
}
}
