[Note: Video has sound!]
During the holidays I’ve been looking into how to make a system that can play multiple sounds, can be accessed from all scripts and is easily maintainable.
To achieve this, I’ve made a manager that has a list of Audio Sources. These can be easily added and tagged, so they can be accessed through some simple functions in the script.
Since the manager is a singleton, this will also ensure that there’s always one and only one manager present in the scene.
I also added a functionality to pick a random sound if multiple sounds with the same tag have been added. This is often done in games to create variation for very repetitive sounds, such as footsteps, hurt sounds, and so on.
All there’s left to do to have all the sounds in our game, is to find or make them, add them to the manager, and call them in the corresponding scripts.