Audio Manager
The AudioManager
script is attached to an indestructible gameobject in the Intro scene living throughout scene changes, handling long (background music) and short (one-time effects) audio playback across the scenes.
By using this manager we are offered with a unique component for playing all kind of AudioClips
easily accessible via static methods. We don't have to provide AudioSource
components in the scenes either, because the manager object has two of them - one for music, one for one-shot sounds already attached to it. For one-shot clips which are usually instantiated and destroyed by default, we are also making use of our own object pooling behavior to reduce garbage collection even more. Except for background music clips, which could be used across scenes and are referenced in the inspector of the AudioManager
directly, all one-shot clips are referenced in their originating scripts: bullet sounds in the Bullet
script, player sounds in the Player
script and so on.