I’ve pieced together some code intending to change the transparency of a slider component, so that rather than just making it vanish I can tween its transparency for fading out. I’m having two issues though. One, I think is a bug and the other is with how verbose my code is. First, the bug. The below code works fine for changing the opacity of my slider to 0 (when toOpacity is 0). But when “toOpacity” is 150 the opacity on the image component isn’t changed to 150. It’s changed to 255. Is this a bug? Or am I doing something wrong.
Image manaImage = Mana.GetComponent<Image>();
Image manaFillImage = Mana.transform.FindChild("Fill Area/Fill").GetComponent<Image>();
manaFillImage.color = new Color(manaFillImage.color.r, manaFillImage.color.g, manaFillImage.color.b, toOpacity);
manaImage.color = new Color(manaImage.color.r, manaImage.color.g, manaImage.color.b, toOpacity);
And finally, is there a simpler way to fade my slider to invisible and back to visibility without having to fade two different objects at the same time? Something like an Opacity property on the ICanvasElement interface that would affect the opacity on all child elements would be awesome but I’m afraid that’s asking too much.