- Home /
Pull a color out of a Color.Lerp fade
Hi, I've seen on other questions how to Lerp between colors like Fading between the two. But I'm looking to do it based on a number.
An example would be I have two colors. Red for the starting color, and Blue for the ending color. I would then assign them values such as
0 = Red, 100 = Blue
Then, I would get a number between 0 and 100, like 65. I would then want to be able to get the color corresponding to 65 between the starting color and the ending color. So, Not so much fading, but pulling a color out of a spectrum of colors based only on a Starting color, an ending color and a value between the two.
Any thoughts on how I might do this?
Answer by zharik86 · Sep 01, 2014 at 07:17 PM
Use function Color.Lerp. I write small example(write on CSharp):
public int cur = 65;
void Start() {
Color myCol = Color.Lerp(Color.red, Color.blue, (float)(cur)/100.0f; //get current color
}
I hope that it will help you.
I will test it out as soon as I'm home. It looks like it might work, And I'm kinda mad at myself for not realizing it could be that simple haha
Your answer
Follow this Question
Related Questions
How to fade an image 1 Answer
Color lerp once? 2 Answers
How to change the alpha element of particles/additive color? 1 Answer
Lerping/Fading between multiple colours 1 Answer
How to make OnTriggerStay ColorLerp start all over again OnTrigger? 2 Answers