Home > other > Why Color. Lerp linear differential value, time set is very large, but change so fast?
Why Color. Lerp linear differential value, time set is very large, but change so fast?
Time:09-22
Purpose: I want to Color. The Lerp (), will be the Color of the Text in the Canvas fade out, and the transparency of Text Color is smooth to 0,
Public Text m_Text;
Void the Update () { FadeText (); }
Void FadeText () { M_Text. Color=color. Lerp (m_Text. Color, the new color (255,0,0,0), 3 f). The Debug Log (m_Text. Color); }
I am can't understand why this text color is the second variable transparency of 0, have know and help me?
CodePudding user response:
Xie ask Lerp function USES the method is correct But the problem here m_Text. Color=color. The Lerp (m_Text. Color, the new color (255,0,0,0), 3 f). Lerp function. The first parameter should not be m_Text color because m_Text. The color is you set to each frame change, so lead to more and more quick time is not a 3 s The correct approach
//in front of the assignment Color Begincolor=m_Text. Color; Public Text m_Text;
Void the Update () { FadeText (); }
Void FadeText () { M_Text. Color=color. Lerp (Begincolor, new color (255,0,0,0), 3 f). The Debug Log (m_Text. Color); }
CodePudding user response:
Eldest brother you to knot a post,,,
CodePudding user response:
Two of Lerp didn't understand, the third parameter is 0 ~ 1 is greater than 1 is 1,
Lerp (a, b, r) Is actually a + r * r (b - a) if is 1 is not b, transient,
You need to use a variable record Float changetime=0 f; Before the change set to 0 Then every Time the update changetime +=Time. DeltaTime;
M_Text. Color=color. Lerp (m_Text. Color, the new color (255,0,0,0), changetime);//this is not uniform, get down in 1 seconds,
If you want to slow down M_Text. Color=color. Lerp (m_Text. Color, the new color (255,0,0,0), changetime/3);//don't get down in three seconds at a constant speed,