2D Toolkit Forum

2D Toolkit => Support => Topic started by: etoreo on May 27, 2012, 07:24:04 am

Title: .color not responding like it should?
Post 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.

Code: [Select]
      // 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;
Title: Re: .color not responding like it should?
Post by: unikronsoftware on May 27, 2012, 02:51:51 pm
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.
Title: Re: .color not responding like it should?
Post by: etoreo on June 05, 2012, 12:57:24 am
And back to feeling stupid.  Thanks for the help.