Unity/스크립트
Color.Lerp 함수를 이용해 A 컬러에서 B컬러로 자연스럽게 변경하기
빨강꼬마
2017. 4. 27. 21:23
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