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.
| Field | Description |
|---|---|
| Audio Source | Source to play through. Uses this object’s AudioSource when empty |
| Sounds | Clips to pick from at random |
| Pitch Range | Random pitch range (min, max) |
| Play On Enable | Play 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.
| Field | Description |
|---|---|
| Effect | Prefab 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.
| Field | Description |
|---|---|
| Lifetime | Seconds before the effect is destroyed |