UnityTowerDefense/Assets/_Project/Scripts/Audio
2026-07-16 20:49:13 -07:00
..
AudioCategory.cs tab once selects builder, tab twice focuses builder 2026-07-16 20:49:13 -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 death sounds, build sounds, better audio management 2026-06-30 23:12:27 -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
MusicPlayer.cs music 2026-06-30 23:27:36 -07:00
MusicPlayer.cs.meta music 2026-06-30 23:27:36 -07:00
README.md music 2026-06-30 23:27:36 -07:00
README.md.meta readme 2026-06-30 20:24:55 -07:00
SoundConfig.cs death sounds, build sounds, better audio management 2026-06-30 23:12:27 -07:00
SoundConfig.cs.meta death sounds, build sounds, better audio management 2026-06-30 23:12:27 -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.

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

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.