This commit is contained in:
Ian Woods 2026-06-30 20:24:55 -07:00
parent 404c749a43
commit ec3f82c591
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,36 @@
# Audio System
Centralised voice-limited audio for the game. Lives in `Assets/_Project/Scripts/Audio/`.
## How it works
`AudioManager` is a per-scene MonoBehaviour singleton. On `Awake` it pre-allocates a pool of `AudioSource` components (on its own GameObject) for each sound category. Callers request playback via `AudioManager.Instance.Play(clip, category, pitch)` — the manager picks the next source in that category's pool using round-robin, interrupting the oldest sound if all voices are busy.
## Categories (`AudioCategory` enum)
| Category | Typical use |
|---|---|
| `TowerFire` | Tower attack sounds |
| `EnemyHitDeath` | Enemy damage and death sounds |
| `UI` | Button clicks, placement confirmation, etc. |
| `Music` | Background music |
Voice limits and volume per category are configured in the Inspector on the `AudioManager` scene GameObject.
## Scene setup
An empty GameObject named `AudioManager` must exist in each gameplay scene with the `AudioManager` component attached. Configure the `Categories` array in the Inspector — one entry per `AudioCategory` value.
Suggested defaults:
- TowerFire: 4 voices, volume 1.0
- EnemyHitDeath: 8 voices, volume 1.0
- UI: 4 voices, volume 1.0
- Music: 2 voices, volume 0.8
## Adding a new sound-emitting component
1. Get a reference to an `AudioClip` via `[SerializeField]`
2. Call `AudioManager.Instance?.Play(clip, AudioCategory.YourCategory)` at the point the sound should trigger
3. Pitch randomization (if desired) is the caller's responsibility: `Random.Range(minPitch, maxPitch)` passed as the third argument
See `TeslaTowerFireSound.cs` in `Scripts/Combat/` as a reference implementation.