1. Home
  2. Docs
  3. FAQ
  4. How to play sound effects

How to play sound effects

Inside the project there is a prefab called ‘AudioPlayer’. This prefab contains a list of all the audio files in the game. You can add new audio items to the list and edit settings like the volume, looping and minimal time between playing this sound again.

If you add multiple audio files to the Clip section, it will randomly play one of the files from the list.

Audio files can now be played from animations or from code.

Playing SFX from animation

You can use animation events to play sound effects.

1. Browse towards your animation file in your project window and select it.
2. In the inspector window select the animation tab.
3. At the bottom open the events tab.

You can now scrub through your animation and press the small left button to add event markers to your animation. Click on the marker to edit it’s data.

To play a sound effect: type ‘PlaySFX’ in the function field.
Type the name of the sound effect (as listed in the audioPlayer) in the string field.
Hit the Apply button to save your changes.

Playing SFX through code

If you are a programmer you can call the following function: GlobalAudioPlayer.PlaySFX(name);
(‘name’ refers to the name of the sound effect as listed in the audioPlayer prefab).

If you want stereo sounds you can call the following function:
GlobalAudioPlayer.PlaySFXAtPosition (name, transform.position);