diff --git a/Assets/Scripts/GameObject/TimedDestroy.cs b/Assets/Scripts/GameObject/TimedDestroy.cs index 3c52f20..99a9ee8 100644 --- a/Assets/Scripts/GameObject/TimedDestroy.cs +++ b/Assets/Scripts/GameObject/TimedDestroy.cs @@ -8,13 +8,24 @@ public class TimedDestroy : MonoBehaviour public float maxLifeSeconds = 3f; public bool releaseIntoGameObjectPooler = false; - IEnumerator Start() + void OnEnable() + { + StartCoroutine(StartDestroy()); + } + + private void OnDisable() + { + StopAllCoroutines(); + } + + private IEnumerator StartDestroy() { yield return new WaitForSeconds(maxLifeSeconds); if (releaseIntoGameObjectPooler) { GameObjectPooler.instance.Release(gameObject); - } else + } + else { Destroy(gameObject); } diff --git a/package.json b/package.json index 78e20ab..5b8a189 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.tangx246.unitytools", - "version": "0.0.44", + "version": "0.0.45", "displayName": "Unity Tools", "description": "A collection of various useful tools for Unity", "author": {