Created
July 11, 2018 03:40
-
-
Save cooloon/961dafae9055109ad9ac5371c7e2b15e to your computer and use it in GitHub Desktop.
[Unity] Pause and Resume coroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class Test : MonoBehaviour | |
{ | |
IEnumerator _routine; | |
IEnumerator routine { get { return _routine ?? (_routine = RoutineImpl()); } } | |
void OnEnable() | |
{ | |
StartCoroutine(routine); | |
} | |
void OnDisable() | |
{ | |
StopCoroutine(routine); | |
} | |
public IEnumerator RoutineImpl() | |
{ | |
while (true) | |
{ | |
Debug.LogFormat("[{0}] Log-A", Time.frameCount); | |
yield return null; | |
Debug.LogFormat("[{0}] Log-B", Time.frameCount); | |
yield return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment