30 lines
1.4 KiB
C#
30 lines
1.4 KiB
C#
// Assets/_Project/Scripts/VFX/TransientEffect.cs
|
|
using UnityEngine;
|
|
|
|
namespace TD.VFX
|
|
{
|
|
/// <summary>
|
|
/// 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
|
|
/// <see cref="SellEffectSpawner"/> (and any future effect spawner) that fire once and
|
|
/// should disappear.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <b>Shuriken shortcut:</b> a plain <see cref="ParticleSystem"/> can instead self-destroy
|
|
/// with no component at all — set <i>Main → Stop Action → Destroy</i> and make sure Looping
|
|
/// is off. Use this component for <b>VFX Graph</b> effects (which have no Stop Action) or for
|
|
/// prefabs that combine several systems and need one predictable lifetime.
|
|
///
|
|
/// <para>Set <see cref="lifetime"/> to comfortably exceed the effect's visible duration so it
|
|
/// isn't cut off mid-play.</para>
|
|
/// </remarks>
|
|
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);
|
|
}
|
|
}
|