Hello Guest

Author Topic: .color not responding like it should?  (Read 4863 times)

etoreo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
.color not responding like it should?
« 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;

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: .color not responding like it should?
« Reply #1 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.

etoreo

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: .color not responding like it should?
« Reply #2 on: June 05, 2012, 12:57:24 am »
And back to feeling stupid.  Thanks for the help.