실행 이미지

using System.Collections;
using UnityEngine;

public class CoroutineTest : MonoBehaviour
{
    float curruntTime = 0f;

    void Start()
    {
        StartCoroutine("TimeWatch");
        StartCoroutine("FirstCo");
    }

    IEnumerator FirstCo()
    {
        // 3초 동안 대기
        yield return new WaitForSeconds(3);
        // 정수로 표시 (반올림)
        Debug.LogFormat("첫번째 코루틴 시작 : {0}초", Mathf.RoundToInt(curruntTime));
        StartCoroutine("SecondCo");
    }

    IEnumerator SecondCo()
    {
        // 추가적으로 2초 동안 대기
        yield return new WaitForSeconds(2);
        // 정수로 표시 (반올림)
        Debug.LogFormat("두번째 코루틴 시작 : {0}초", Mathf.RoundToInt(curruntTime));
    }

    IEnumerator TimeWatch()
    {
        while (true)
        {
            curruntTime += Time.deltaTime;
        }
    }
}
반응형

+ Recent posts