Hi, I am trying to make a sort of health bar with a slider from the new UI system. I wanted to get fancy and have the slider background color start as green and then change to red once the health is below a certain threshold. However I cannot figure out how to change the background color of the Fill Area of the slider via code. I did some googling but no luck so far.
What you want is to change the Color of the Image component of the “Background” Child of the Slider and set it to red. And the Slider->Fill Area->Fill Child has also an Image Compinent with an Attribute called Color that you want to set to green for example.
This is how I could do that
public Slider slider;
Color color = new Color(233f/255f, 79f/255f, 55f/255f);
slider.gameObject.transform.Find("Fill Area").Find("Fill").GetComponent<Image>().color = color;