Unity audio basics

To play an audio clip in Unity, you only need to add an “Audio Source“ component to a game object, enable “Play On Awake”, and drag the desired audio clip into the AudioClip field.

To play an audio clip through code, in a response to something happening in the app is not much more complicated.

First you need a reference to an audio source.
Here I placed my audio source on a separate game object and dragged it into the open field in the inspector.

Then I call the PlayOneShot function on the audio source because I want to let the sound effect overlap with itself instead of restarting if its being played again before finishing.

--

--

Kasper Møberg Rasmussen

Masters graduate of Learning and experience technology from University of southern Denmark, with a passion for the future of interaction.