Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

codingfarm

코루틴 본문

Unity3d

코루틴

scarecrow1992 2022. 2. 20. 23:33

 

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

특정 효과를 점진적으로 주고 싶을경우 주로 사용한다.

주로 점차적인 애니메이션 혹은, 분산 연산(로딩 화면 etc)등에 사용됩니다.

 

1
StartCoroutine(DeathAnimation());
cs

 

1
2
3
4
5
6
7
8
9
public IEnumerator DeathAnimation() {
    int current = 0;
 
    for (; current > -90; current = current - 5) {
        transform.Rotate(new Vector3(-500));
        yield return null;
    }
    Die();
}
cs

yield return null; 에서 DeathAnimation이 반환되면, 다음번에 DeathAnimation이 호출될경우 yield return null;이 호출되었던 곳 부터 시작됩니다.

그동한 함수 내의 모든 변수값들은 자신의 상태를 저장하게 됩니다.

 

 

yield return new WaitForSeconds(float); 로 반환하면, 코루틴 호출 간격을 조절 할 수 있다.

1
2
3
4
5
IEnumerator UpdatePath() {
    // ...
 
    yield return new WaitForSeconds(refreshRate);
}
cs

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Unity3d' 카테고리의 다른 글

시간  (0) 2022.02.21
생성  (0) 2022.02.21
이동  (0) 2022.02.21
Ray  (0) 2022.02.21
5. 2d 플랫포머 - 내리막 길  (0) 2020.08.02
Comments