Author Topic: Is there an easy way to smoothly change the color of a sprite?  (Read 3015 times)

hurleybird

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
I want to change the color of a sprite from green to red based off a value between 1 and 100. Before I go about coding this, is there an easy way to do this in NGUI that I'm not aware of?

dkozlovtsev

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
    • View Profile
Re: Is there an easy way to smoothly change the color of a sprite?
« Reply #1 on: June 20, 2014, 04:04:46 AM »
Look into tween color script

hurleybird

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Is there an easy way to smoothly change the color of a sprite?
« Reply #2 on: June 20, 2014, 05:26:45 PM »
I don't think that will work, as tween color will change the sprite from one color to another over a specific duration when given a specific trigger. It's just a simple animation. I want to have the sprite be one color at value 1, another color at value 0, and slowly change from one to the other as that value goes from 1 to 0. That said, some of the code from tween color may be able to reused to help me create a new script with the functionality I need. Let me know if I'm mistaken or there's some other included script that functions the way I want it to though!

Edit:

I got the color changing script created, but how do I actually assign that color to a UI2DSprite element?
« Last Edit: June 20, 2014, 07:44:32 PM by hurleybird »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Is there an easy way to smoothly change the color of a sprite?
« Reply #3 on: June 21, 2014, 03:32:54 PM »
UI2DSprite is a widget.

GetComponent<UI2DSprite>().color = Color.red;

or just like any other widget:

GetComponent<UIWidget>().color = Color.red;

hurleybird

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Is there an easy way to smoothly change the color of a sprite?
« Reply #4 on: June 21, 2014, 06:54:51 PM »
UI2DSprite is a widget.

GetComponent<UI2DSprite>().color = Color.red;

or just like any other widget:

GetComponent<UIWidget>().color = Color.red;

Thanks!