- Home /
Change color between 2 values mid game.
I know this must be incredibly simple but I'm very lost.
What i want to do is get a color to go from value a to b at a certain moment. I realized that I can do this at the start using this
transform.renderer.material.color = Color.Lerp(Color.black, keywordColor, Time.time);
Since Time.time is still 0 when the game starts.
Later on I want to do this again but since Time.time is already higher than one I can never get the transition from value a to value b...
I tried to go even simpler and being able to do a Mathf.Lerp between 1 and 0 and cant figure it out, whenever i try to do it other than right at the start of a game it doesn't work.
Answer by Loius · Feb 01, 2013 at 08:30 PM
Capture the time at the start and treat that as zero.
A la:
function StartLerp() {
lerpstart = Time.time;
}
function UpdateLerp() {
if ( Time.time - lerpStart > 1 ) lerpStart = Time.time - 1; // and send some message that it's time to stop the lerp
color = Color.Lerp( from, to, Time.time - lerpstart );
}
Gotcha, thanks for the idea, I ended up changing the StartLerp() slightly to fit my needs but it worked perfectly!
Just understood.. by multiplying with a number higher than 1!
Your answer
Follow this Question
Related Questions
Lerp Color doesn't work 2 Answers
How can I change the color of a light over time? 3 Answers
How do I loop a Color32.Lerp? 3 Answers
How to make two colors lerp independently in this code? 1 Answer
Color.Lerp doesn't work 1 Answer