Effects

Three small helpers for the feedback around damage and death. Hook their methods to the events of Health, Hitbox or Pickup.

  flowchart LR
    A["On Death"] --> B["SpawnableEffect"] --> C["Effect prefab"]

This is exactly how the example ducks die: On Death spawns DS_DuckDeathEffect, whose SoundGenerator plays a random squeak and whose DeathEffect cleans it up after 2 seconds.

πŸ”Š Sound Generator

Plays a random clip at a random pitch, so repeated hits don’t sound identical.

FieldDescription
Audio SourceSource to play through. Uses this object’s AudioSource when empty
SoundsClips to pick from at random
Pitch RangeRandom pitch range (min, max)
Play On EnablePlay when the object is enabled. Handy on spawned effect prefabs

Call Play() from an event, for example a hitbox’s On Hit.

✨ Spawnable Effect

Spawns an effect prefab at this object’s position and rotation when Spawn() is called.

FieldDescription
EffectPrefab to spawn

Tip

Hook On Death to SpawnableEffect.Spawn to leave an explosion behind when an enemy is destroyed.

⏳ Death Effect

Destroys its own GameObject after a set time. Put it on spawned effect prefabs so they clean themselves up.

FieldDescription
LifetimeSeconds before the effect is destroyed