Created
December 11, 2013 20:08
-
-
Save ereidland/7917513 to your computer and use it in GitHub Desktop.
Static Coroutine in Unity
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 StaticCoroutine : MonoBehaviour | |
{ | |
private static StaticCoroutine _instance; | |
public static void Do(IEnumerator enumerator) | |
{ | |
if (_instance == null) | |
{ | |
var obj = new GameObject("Static Coroutine Object"); | |
obj.hideFlags = HideFlags.HideInHierarchy; | |
_instance = obj.AddComponent<StaticCoroutine>(); | |
} | |
_instance.StartCoroutine(enumerator); | |
} | |
private void Awake() { _instance = this; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there :)
Can you explain why / when you use a static coroutine?
cheers