Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: hurleybird on June 20, 2014, 02:15:22 AM

Title: Is there an easy way to smoothly change the color of a sprite?
Post by: hurleybird on June 20, 2014, 02:15:22 AM
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?
Title: Re: Is there an easy way to smoothly change the color of a sprite?
Post by: dkozlovtsev on June 20, 2014, 04:04:46 AM
Look into tween color script
Title: Re: Is there an easy way to smoothly change the color of a sprite?
Post by: hurleybird 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?
Title: Re: Is there an easy way to smoothly change the color of a sprite?
Post by: ArenMook 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;
Title: Re: Is there an easy way to smoothly change the color of a sprite?
Post by: hurleybird 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!