Unity/스크립트

Color.Lerp 함수를 이용해 A 컬러에서 B컬러로 자연스럽게 변경하기

빨강꼬마 2017. 4. 27. 21:23
  1. float duration = 5; // This will be your time in seconds.
  2. float smoothness = 0.02f; // This will determine the smoothness of the lerp. Smaller values are smoother. Really it's the time between updates.
  3. Color currentColor = Color.white; // This is the state of the color in the current interpolation.
  4. void Start()
  5. {
  6. StartCoroutine("LerpColor");
  7. }
  8. IEnumerator LerpColor()
  9. {
  10. float progress = 0; //This float will serve as the 3rd parameter of the lerp function.
  11. float increment = smoothness/duration; //The amount of change to apply.
  12. while(progress < 1)
  13. {
  14. currentColor = Color.Lerp(Color.red, Color.blue, progress);
  15. progress += increment;
  16. yield return new WaitForSeconds(smoothness);
  17. }
  18. return true;
  19. }


출처

http://answers.unity3d.com/questions/328891/controlling-duration-of-colorlerp-in-seconds.html