상세 컨텐츠

본문 제목

유니티 코루틴

유니티/기능

by MJ_119 2024. 9. 4. 14:23

본문

 

while (linearTime < 1f)
{
    linearTime += Time.deltaTime * speed;
    transform.position = Vector3.Lerp(startPosition, endPosition, linearTime);
    yield return new WaitForEndOfFrame();  // 모든 업데이트 후, 렌더링 전에 대기
}

while (linearTime < 1f)
{
    linearTime += Time.deltaTime * speed;
    transform.position = Vector3.Lerp(startPosition, endPosition, linearTime);
    yield return null;  // 다음 프레임까지 대기
}

 

 

  • yield return null;: 일반적으로 매 프레임 업데이트에 사용되며, 프레임 간격을 기다리기 위한 가장 기본적인 방법입니다.
  • yield return new WaitForEndOfFrame();: 현재 프레임의 모든 업데이트가 끝난 후, 다음 프레임이 렌더링되기 직전에 실행하고 싶을 때 사용합니다.

두 코드 모두 프레임을 기다리면서 transform.position을 업데이트하는 동작을 수행하겠지만,

yield return null;은 보다 일반적으로 사용되는 방법입니다.

yield return new WaitForEndOfFrame();은 특별히 프레임 끝에 작업을 해야 할 때 사용하는 것이 좋습니다.

관련글 더보기