UnityTowerDefense/Assets/_Project/Scripts/Audio
2026-06-30 20:24:55 -07:00
..
AudioCategory.cs unified audio manager that limits the number of simultaneous sounds in certain categories 2026-06-30 20:12:03 -07:00
AudioCategory.cs.meta unified audio manager that limits the number of simultaneous sounds in certain categories 2026-06-30 20:12:03 -07:00
AudioManager.cs unified audio manager that limits the number of simultaneous sounds in certain categories 2026-06-30 20:12:03 -07:00
AudioManager.cs.meta unified audio manager that limits the number of simultaneous sounds in certain categories 2026-06-30 20:12:03 -07:00
README.md readme 2026-06-30 20:24:55 -07:00
README.md.meta readme 2026-06-30 20:24:55 -07:00

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.