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

'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
빨강꼬마

,