// Assets/_Project/Scripts/VFX/TransientEffect.cs using UnityEngine; namespace TD.VFX { /// /// Destroys its GameObject a fixed time after it spawns. Drop this onto any one-shot /// effect prefab — a particle burst, a VFX Graph effect, a sound-only object — so it /// cleans itself up without any bespoke code. Designed for prefabs spawned by /// (and any future effect spawner) that fire once and /// should disappear. /// /// /// Shuriken shortcut: a plain can instead self-destroy /// with no component at all — set Main → Stop Action → Destroy and make sure Looping /// is off. Use this component for VFX Graph effects (which have no Stop Action) or for /// prefabs that combine several systems and need one predictable lifetime. /// /// Set to comfortably exceed the effect's visible duration so it /// isn't cut off mid-play. /// public class TransientEffect : MonoBehaviour { [Tooltip("Seconds after spawn before this GameObject destroys itself. Set it a little " + "longer than the effect's visible length so nothing is cut off.")] [SerializeField, Min(0f)] private float lifetime = 1.5f; private void Start() => Destroy(gameObject, lifetime); } }