float duration = 5; // This will be your time in seconds.
float smoothness = 0.02f; // This will determine the smoothness of the lerp. Smaller values are smoother. Really it's the time between updates.
Color currentColor = Color.white; // This is the state of the color in the current interpolation.
void Start()
{
StartCoroutine("LerpColor");
}
IEnumerator LerpColor()
{
float progress = 0; //This float will serve as the 3rd parameter of the lerp function.
float increment = smoothness/duration; //The amount of change to apply.
while(progress < 1)
{
currentColor = Color.Lerp(Color.red, Color.blue, progress);
progress += increment;
yield return new WaitForSeconds(smoothness);
}
return true;
}
출처
http://answers.unity3d.com/questions/328891/controlling-duration-of-colorlerp-in-seconds.html
'Unity > 스크립트' 카테고리의 다른 글
코루틴 문제 (0) | 2018.06.21 |
---|---|
코루틴과 플래그 처리를 이용한 순차처리 구조. (0) | 2017.11.30 |
Facebook 초기화시 accesstoken 문제 (0) | 2016.08.23 |
Delegate 비교 (1) | 2016.05.17 |
Unity 에서의 멀티쓰레드 구현 (0) | 2016.04.20 |
WRITTEN BY
,