본문 바로가기
개발/C#

유니티 C# 코루틴 Coroutine 간단 사용법

by SPNK 2022. 7. 6.
반응형

코드 작성

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour
{
    private void Start()
    {
        StartCoroutine(ExampleCoroutine());
        StartCoroutine(Example2Coroutine());
        
        StopAllCoroutine(); //모든 코루틴 정지
    }

    IEnumerator ExampleCoroutine()
    {
        Debug.Log("코루틴 실행중");

        yield return new WaitForSeconds(1f);
        StartCoroutine(ExampleCoroutine());
    }

    IEnumerator Example2Coroutine()
    {
        while(true)
        {
            Debug.Log("코루틴을 While문에서 실행중");

            yield return new WaitForSeconds(1f);
        }
    }
}

 


참고할만한 글

 

 

유니티 C# 시간 DateTime 출력하기 간단 사용법

코드 작성 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { DateTime today; DateTime now; private void Start() //날짜 디버그 출력 { today = S

parksh3641.tistory.com

 

 

유니티 C# 카메라 흔들기 Camera Shake 간단 사용법

코드 작성 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public float shakeAmount = 3.0f; public float shakeTime = 1.0f; private void Start() { S

parksh3641.tistory.com

 

반응형

댓글