- Home /
Question by
Stardog · Jan 05, 2013 at 06:18 PM ·
lerponguicolor.lerp
Color.lerp help (GUI.color)
Can someone explain why the first code works but the second doesn't?
This works well. When choosing a colour in the inspector it slowly lerps.
IEnumerator Fade()
{
while (RenderSettings.ambientLight != targetColor)
{
RenderSettings.ambientLight = Color.Lerp(RenderSettings.ambientLight, targetColor, speed * Time.deltaTime);
yield return null;
}
}
This doesn't work at all. I'd have to increment the speed value from 0 to 1. And the condition check seems not not detect any changes in targetColor.
void OnGUI()
{
if (GUI.color != targetColor)
{
GUI.color = Color.Lerp(GUI.color, targetColor, speed * Time.deltaTime);
}
}
Comment
Best Answer
Answer by Stardog · Jan 05, 2013 at 06:42 PM
Oops solved it. I needed to use a temp variable.
public Color targetColor = new Color(0, 0, 0, 0);
public Color tempColor;
void OnGUI()
{
if (tempColor!= targetColor)
{
tempColor= Color.Lerp(tempColor, targetColor, targetSpeed * Time.deltaTime);
}
GUI.color = theGUIColor;
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "Fading");
}
Your answer
Follow this Question
Related Questions
Lerping 2 values on a shader on button press. 1 Answer
Color LERP problem 1 Answer
lerp transparency back and forth, while cycling through rainbow? 0 Answers
OnGui.Button Lerp Object 1 Answer
Trouble with OnGUI and Update 3 Answers