using UnityEngine; using System.Collections; [RequireComponent(typeof(ParticleSystem))] public class AutoDestroyParticle : MonoBehaviour { [SerializeField] private bool onlyDeactivate; [SerializeField] private float destoryPlusTime; [SerializeField] private ParticleSystem particle; private void Awake() { particle = GetComponent(); } void OnEnable() { if (onlyDeactivate) { Invoke(nameof(DisableSelf), particle.main.duration + destoryPlusTime); } else { Destroy(gameObject, particle.main.duration + destoryPlusTime); } } void DisableSelf() { gameObject.SetActive(false); } }