Unity- Coroutines(코루틴)
https://docs.unity3d.com/Manual/Coroutines.html
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
'C# 기초 복습' 카테고리의 다른 글
이벤트 함수의 실행 순서, ?., ??, ??= 연산자, GetComponentsInChildren/ getchild, activeSelf/activeInHierachy (0) | 2023.08.28 |
---|---|
Quaternion.identity, LookRotation, 비트 연산자 (0) | 2023.08.21 |
2주차 복습 (0) | 2023.07.31 |
JSON예제, 대리자 복습 (0) | 2023.07.27 |
배열 예제 복습 (0) | 2023.07.25 |