Unity- Coroutines(코루틴)
2023. 8. 8.

https://docs.unity3d.com/Manual/Coroutines.html

 

Unity - Manual: Coroutines

Coroutines A coroutine allows you to spread tasks across several frames. In Unity, a coroutine is a method that can pause execution and return control to Unity but then continue where it left off on the following frame. In most situations, when you call a

docs.unity3d.com

 

1. 코루틴은 IEnumerator라는 반환형으로 시작해야한다.

2. yield retrun이 반드시 함수 내부에 존재해야한다.

 

-IEnumorator 는 우리말로 열거자라고 하는데, 데이터의 목록을 하나씩 넘겨줄 때 사용되는 인터페이스이다.

-코루틴은 호출한 함수와 서로 상호작용하면서 진행하도록 설계되어 있다.

-코루틴 내부에 for문이나 while문을 사용해준다면 마치 업데이트문처럼 매 프레임마다 반복되게 할 수 있다.

 

코루틴 호출

StartCoroutine( 메소드이름( 매개변수1, 매개변수2 ) );
StartCoroutine( "메소드이름", 매개변수 );
  • yield return 의 종류

1. yield return null;  :  다음 프레임에 실행

2. yield return new WaitForSeconds( float );  :  매개변수로 입력한 숫자에 해당하는 초만 큼 기다렸다가 실행

3. yield return new WaitForSecondsRealtime( flaot );  :  매개변수로 입력한 숫자에 해당하는 초만큼 기다렸다가 실행

4. 그외 : yield return + new WaitForFixedUpdate / WaitForEndOfFrame 등

5. yield break;

 

 

 

 

 

https://coding-of-today.tistory.com/171

 

[유니티] 코루틴의 사용법 총정리 - Unity Coroutine

코루틴(Coroutine) 1. 어디에 쓰이는가? 우선, 코루틴이 어떤 상황에서 필요한지 알아보자. 유니티에서 특정 코드가 반복적으로 실행되기 위해서는 Update문에 코드를 작성하면 되는데, 간혹 Update가

coding-of-today.tistory.com

https://seungngil.tistory.com/entry/Unity-IEnumberator-%EC%BD%94%EB%A3%A8%ED%8B%B4Coroutine%EC%9D%98-%EA%B8%B0%EB%B3%B8-%EA%B0%9C%EB%85%90-%EB%B0%8F-%ED%99%9C%EC%9A%A9

 

[Unity3D] IEnumberator, 코루틴(Coroutine)의 기본 개념 및 활용

코루틴(Coroutine)이 뭔가요? C 언어등에서 일반적으로 사용하는 함수는 시작할 때 진입하는 지점이 하나 존재하고 함수가 모두 실행되거나, return 구문에 의해서 종료되는 지점을 설정할 수 있습니

seungngil.tistory.com

 

myoskin