- Home /
Transitioning colors based on variable.
Hi, I need to change the color of a GUITexture based on the value of a float. What I basically want is that when the float is at it's limit (which is 30) it would be totally the second color, and if that variable is at 0 it would be exactly the first color, and apply this for every value between 0 and 30. Any tips on how to do this? I have no idea how to begin, so far I've only made the variable for the 2 colors and the other value (but that value was there from the beginning) and also the variable to assign the GUITexture so that I can change its color.
Thanks in advance.
Answer by AndyMartin458 · Jul 23, 2014 at 07:59 PM
I'm sure you could find a way to make the lerp system work like you want. The hard part is that colors don't just naturally transition between each other simply by changing a couple of parameters.
The way to make Color.Lerp work like that is set the "t" parameter as value/30, where value is your 0-30 value.
For 0 it returns full first color, for 30 it return full second.
Thanks a lot you two, Techinque, that worked perfectly, I'm used of only using lerp to usually move stuff around smoothly, where I have a destination and basically you can't go back, never actually had to do something like this, but yeah it works perfectly. Thanks!