Audio

Our Audio Controller manages and plays sounds, allowing sounds to be triggered, paused, or stopped. Including other features such as random pitch & easily separate sounds into different tracks.

For us to play sounds, we need to store the sounds somewhere. This is where the Audio Master helps us. Add the Audio Master script to an object in the scene.

Here, we can add/remove/update sounds and differentiate sound effects into different tracks allowing multiple sounds to play in parallel with different settings.

For us to add sounds, we need to create one. Go to Create/Essentials/Audio/Sound. This will create a Sound object. Here we can add multiple audio clips (it will select one at random) and change a lot of other settings (all with tooltips if you hover the property).

Be sure to name your sound to be able to easily play a sound from any other script by referencing its name.

To add the sound we simply add it to the Audio Master. You can choose any track or create a new one.

To now play the sound, we simply add the following line anywhere:

AudioMaster.PlaySound("soundnamehere");

Automatically add play sound calls

Sometimes, you would simply like to play a sound without digging around in your own code all the time. This is where the Audio Player comes in handy. Add the Audio Player script to any game object. Now you can add a new entry. Select the sound you want to play and add an event. You can now Subscribe to that sound and it will automatically generate a line of code that simply calls the Audio Master to play the sound.

Last updated