unity C#

[Unity] 중첩 코루틴 Coroutine

bamsik 2023. 1. 30. 17:01
반응형

중첩 코루틴

코루틴 내부에서 또다른 코루틴을 호출한다. 해당 코루틴이 완료될 때까지 기다리게 된다. 의존성이 있는 여러 작업을 수행하는데 유리하게 사용 될 수 있다.

 

void Start () {
	StartCoroutine (TestRoutine());
}

IEnumerator TestRoutine() {
	Debug.Log ("Run TestRoutine");
	yield return StartCoroutine (OtherRoutine ());
	Debug.Log ("Finish TestRoutine");
}

IEnumerator OtherRoutine() {
	Debug.Log ("Run OtherRoutine #1");
	yield return new WaitForSeconds (1.0f);
	Debug.Log ("Run OtherRoutine #2");
	yield return new WaitForSeconds (1.0f);
	Debug.Log ("Run OtherRoutine #3");
	yield return new WaitForSeconds (1.0f);
	Debug.Log ("Finish OtherRoutine");
}
반응형