Skip to content

Instantly share code, notes, and snippets.

@ereidland
Created December 11, 2013 20:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ereidland/7917513 to your computer and use it in GitHub Desktop.
Save ereidland/7917513 to your computer and use it in GitHub Desktop.
Static Coroutine in Unity
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; }
}
@DomDomHaas
Copy link

Hi there :)

Can you explain why / when you use a static coroutine?

cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment