Adding the feature to sell towers with VFX and audio included

This commit is contained in:
Matt F 2026-07-14 23:15:34 -07:00
parent 1794f65b19
commit 0b4cde4590
16 changed files with 5394 additions and 13 deletions

View file

@ -65,7 +65,15 @@ namespace TD.VFX
if (coinBurstPrefab != null)
{
Instantiate(coinBurstPrefab, spawnPos, Quaternion.identity);
var instance = Instantiate(coinBurstPrefab, spawnPos, Quaternion.identity);
// Force the burst to play. The spawner's whole job is to play this effect, so
// it shouldn't depend on the prefab's ParticleSystem having "Play On Awake"
// ticked — if that's off, the effect would silently never appear. Harmless when
// Play On Awake is already on (a freshly instantiated one-shot just restarts at
// t=0). VFX Graph effects play from their own settings, so a null PS is fine.
var ps = instance.GetComponentInChildren<ParticleSystem>();
if (ps != null) ps.Play(withChildren: true);
}
else
{

View file

@ -0,0 +1,30 @@
// 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);
}
}

View file

@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 739f3145f66002d47850b603164d07b8