- Home /
NGUI Slider foreground color change
I am using NGUI sliders and want to change the color when the slider gets to specific values. When I code the color changing using the color constants i.e. Color.Red or Color.Green, everything works ok. But when I add public color variables to my class prefab and set the colors the color change appears to hide the foreground slider copmponent.
When I inspect the foreground during runtime, the tinitcolor in the inspector shows the color but the slider only shows the background component.
The following shows the Code...
// foreground component and normal bar color.
public UISprite barForeground;
public Color normalBarColor;
// This code works..
barForeground.color = Color.green;
// this code does not work and appears to 'hide' the component
barForeground.color = normalBarColor;
Thanks
Answer by samuelmorais · Oct 03, 2013 at 07:15 PM
I am having exactlythe same problem.
Edit:
The answer is here: http://www.tasharen.com/forum/index.php?topic=2831.0
The problem is with the alpha channel. You have to set alpha value to 1f, like this:
GameObject.Find("WidgetName").GetComponent().color = new Color(someValueToR,someValueToG,someValueToB,1f);