volume-offAudio System

Three main prefabs are used for working with audio: AudioManager, MusicAudioSource, and SFXAudioSource3D. Path: Assets/StaticAssets/Prefabs/Audio

AudioManager component

The AudioManager prefab includes the AudioManager component, which is responsible for centralized sound management in the project.

  • Maintains a list of sounds (music, effects, UI sounds, etc.);

  • Contains playback parameter settings;

  • Controls playback through designated audio sources.

Prefab references:

  • MusicAudioSource2D — handles background music playback;

  • SFXAudioSource3D — used for playing 3D sounds in the game world (e.g., gunshots, explosions, footsteps, etc.).

Usage in the project

In the project, the AudioManager prefab is located in the following contexts:

  • PlayerContext

  • EnemyStickmanContext

  • TentacleContext

  • RocketContext

  • Scene Level

Local AudioManagers

AudioManager components located within the following contexts:

  • PlayerContext

  • EnemyStickmanContext

  • TentacleContext

  • RocketContext

— are used only within their respective contexts and are not intended for global access. They manage local sounds specific to the behavior of their corresponding objects (e.g., enemy footsteps, tentacle attacks, player sounds, etc.).


[Global] AudioManager

The global AudioManager, marked as [Global], is registered in the Zenject container of the level (SceneContext).

  • Available to all systems within the Level scene;

  • Can be injected via DI (Dependency Injection) into any classes requiring sound playback (e.g., cutscenes, UI, triggers, etc.);

  • Used for playing non-contextual or universal sounds such as:

    • UI buttons;

    • Victory/defeat;

    • Background music.


Sound registration in AudioManager

To play sounds via AudioManager, each sound must be registered in the Sounds list of the component. Registration includes specifying all necessary parameters to ensure correct playback and convenient access to the sound in code. Sound element parameters (SoundData):

Field
Description

Name

A unique key used to play the sound from code.

SoundType

Specifies which type of AudioSource to use: – MusicAudioSource2D — for background music; – SFXAudioSource3D — for 3D sounds in the game world.

SoundPlayMode

Specifies the playback method: – AudioSource.Play() — starts the sound on the source; – AudioSource.PlayOneShot() — plays a single instance without interrupting the current sound.

Clip

Reference to the audio file (AudioClip)

Parameters

Nested settings: – Volume — volume level; – Pitch — pitch (sound frequency); – Loop — whether the sound should loop continuously.


Constants for accessing sounds

After registering a sound in AudioManager, its key (Name) should be added to a special class like GameConstants.Sounds to avoid errors from using string literals in the code.

Advanced Audio Configuration

For more precise and professional sound settings in the project, use the AudioMixer window. Unity MenuWindowAudioAudio Mixer

Audio Mixer capabilities:

  • Separating sounds into groups: music, effects, voice, UI, etc.

  • Adjusting volume, fading, and transitions between audio groups.

  • Applying processing effects (equalizer, reverb, compression, etc.).

  • Managing sound mute timing or fading during events (e.g., pause or player death).

  • Supporting export of parameters to code for programmatic control (see Exposed Parameters).

Default audio parameters: Music and Sfx

The project has two main preset volume parameters used in the Audio Mixer and controlled via code:

  • Music: Controls the volume level of background music.

  • Sfx: Manages the volume of sound effects such as gunshots, explosions, and UI sounds.

Last updated