public CoroutineService() { var gameObject = new GameObject(typeof(CoroutineServiceMonoBehaviour).Name); _serviceObject = gameObject.AddComponent <CoroutineServiceMonoBehaviour>(); Object.DontDestroyOnLoad(gameObject); }
/// <summary> /// Cleans the coroutine service and deletes the coroutine game object that contains all the coroutines in the game. /// This will also stop all currently running coroutines. /// </summary> public void Dispose() { if (_serviceObject == null) { return; } _serviceObject.StopAllCoroutines(); Object.Destroy(_serviceObject.gameObject); _serviceObject = null; }