Skip to content

Instantly share code, notes, and snippets.

@FlaShG FlaShG/CoroutineWorker.cs
Last active Sep 25, 2018

Embed
What would you like to do?
Based on MyStaticCode.cs, a class that allows anything to run coroutines from anywhere.
using UnityEngine;
using System.Collections;
public static class CoroutineWorker
{
private class Worker : MonoBehaviour { }
private static Worker worker;
[RuntimeInitializeOnLoadMethod]
private static void Initialize()
{
var go = new GameObject("Coroutine Worker");
worker = go.AddComponent<Worker>();
go.hideFlags = HideFlags.HideAndDontSave;
Object.DontDestroyOnLoad(go);
}
public static Coroutine StartCoroutine(IEnumerator routine)
{
return worker.StartCoroutine(routine);
}
public static void StopCoroutine(Coroutine routine)
{
worker.StopCoroutine(routine);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.