The basics of playing a sound are very straightforward in Unity (adding an AudioSource component to a GameObject and linking it to an AudioClip sound file). For simple sound effects such as short, one-off plays of pickup confirmation noises, it's useful to have a single AudioSource component and reuse it to play different sound effects – which is what we'll do in this recipe.
Playing different one-off sound effects with a single AudioSource component
Getting ready
Try this with any short audio clip that is less than one second in duration. We have included some classic Pacman game sound clips inside the 04_01 folder.