반복문을 가지는 코루틴 대기 하는 방법 - Coroutine Loop
반복문을 가지는 코루틴 대기 하는 방법
하나의 코루틴에서 서브로 반복문을 가지는 코루틴을 호출 하고 그 코루틴이 리턴 할 때까지 기다려야 할 때가 있다.
void Start()
{
StartCoroutine( RunFirst() );
}
IEnumerator RunFirst()
{
yield return StartCoroutine( RunSubFuntion() );
}
IEnumerator RunSubFuntion()
{
for(int i = 0; i < 10 ; i ++)
{
yield return new WaitForSeconds(1f);
}
}
위와 같이 yield return StartCoroutine() 으로 코루틴을 호출 하면 스킵 하지 않고 리턴 할 때 까지 기다리게 된다.
Coroutine Loop
IEnumerator RunLoop()
{
whie(true)
{
yield return null ; // unity의 update() 할수가 끝나면 return 함. 결과적으로 매 루프 처리됨.
}
}
코루틴에서 반복문으로 계속 처리되게 하려면 위와 같이
yield return null
yield return new WaitForSeconds(time)
과 같은 yield return 문을 넣어 줘야 한다.
“파트너스 활동을 통해 일정액의 수수료를 제공받을 수 있음"
그렇지 않고
while(true)
{
}
만 사용 하면 unity가 무한루프로 멈춰 버린다.
yield return null 의미:
스크립트의 update() 문이 처리 되고 나면 리턴 하고 다음 구문으로 진행 할 수 있게 된다.
즉, while 문 안 코드들이 매 프레임 실행 되게 된다.
tag:
unity c# coroutine loop
waiting loop for a coroutine to end
coroutine looping
coroutine loop unity
unity c# coroutine loop
coroutine was never awaited
coroutine never awaited
coroutine exception loop
coroutine for loop
coroutine to loop
c# coroutine loop
coroutine while loop
coroutine while
while loop coroutine unity
unity3d loop coroutine
unity coroutine loop
unity loop coroutine