Unity Coroutine 함수를 활용한 Object의 Lerp(선형보간)운동 구현구현
가장 심플하게 구현한 예제.
C#의 Generic , Reflection을 활용하여 기능 확장 가능.
Code.
IEnumerator moveCoroutine(float duration, Vector3 end) { WaitEndOfFrame wait = new WaitEndOfFrame(); Vector3 start = transform.position; float elapsed = 0.0f; while(elapsed < duration){ elapsed += Time.deltatime; transform.position = Vector3.Lerp(start,end elapsed / duration); yield return wait; } transform.position = end; } IEnumerator colorCoroutine(float duration, Color start, Color end) { WaitEndOfFrame wait += new WaitEndOfFrame(); float elapsed = 0.0f; while(elapsed < duration){ elapsed = Time.deltaTime; renderer.material.color = Color.Lerp(start,end elapsed / duration); yield return wait; } renderer.material.color = end; }
0 개의 댓글:
댓글 쓰기