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,

CodePudding user response:

reference zhenmu reply: 3/f
two 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,

Sorry is I think wrong at that time may be a little mistaken for the original poster I answer cause errors and trouble I apologize to the original poster
Correct because it is
Public float duration=3.0 f;
Float currentTime=0;
Float precent=0;
Color Begincolor=m_Text. Color;
Public Text m_Text;

Void the update () {
CurrentTime +=Time. DeltaTime;
If (currentTime & gt; Duration)
CurrentTime=duration;
Percent=currentTime/duration;
ChangeColor (percent);
}

Void percent (float percent) {
M_Text. Color=color. Lerp (Begincolor, new color (255,0,0,0), percent);
The Debug Log (m_Text. Color);
}

This should be a uniform finish 3 s change

CodePudding user response:

reference zhenmu reply: 3/f
two 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,

 
Using UnityEngine;
using System.Collections;
Using UnityEngine. UI;
Public class TColor: MonoBehaviour {

Public float duration=3 f;
Float currentTime=0;
Public float percent=0;
Public Text m_Text;
Color a;

Void the Start () {
A=m_Text. Color;
}

Void the Update () {
CurrentTime +=Time. DeltaTime;
If (currentTime & gt; Duration)
CurrentTime=duration;
Percent=currentTime/duration;
ChangeColor (percent);
}

Void ChangeColor (float percent) {
M_Text. Color=color. Lerp (a, color. Red, percent);
The Debug Log (m_Text. Color);
}
}

This test after May 3 seconds well
Floor Lord
If this is you write
M_Text. Color=color. Lerp (m_Text. Color, the new color (255,0,0,0), changetime/3);
The first parameter is the Lerp function m_Text won't 3 s is less than 3 s

CodePudding user response:

And the building Lord since you need the transparency that is RGBA
Red transparent RGBA is new Color (1,0,0,0)
Instead of the new Color (255,0,0,0)
  • Related