2D Toolkit Forum
2D Toolkit => Support => Topic started by: etoreo on May 27, 2012, 07:24:04 am
-
I am trying to set the color of a white sprite. It should be a smooth transition from green to red and back again, but when I run it, it only has 3 solid colors: green, yellow, and red. No colors in between - even though the values I am setting should give a smooth transition. Am I doing something wrong? The value os percent and colorPercent of the following code are correct when I debug it.
// Change the color based on health
float percent = mHeath / mMaxHealth;
float colorPercent = percent * 255.0f;
Color pColor = mHealthSprite.GetComponent<tk2dSprite>().color;
pColor.b = 0.0f;
pColor.g = colorPercent;
pColor.r = 255.0f - colorPercent;
mHealthSprite.GetComponent<tk2dSprite>().color = pColor;
-
As explained on this page here:
http://unity3d.com/support/documentation/ScriptReference/Color.html
The color type has a range of 0..1 in each component. Getting rid of the 255 and replacing it with 1.0 will solve your problem.
-
And back to feeling stupid. Thanks for the help.