Time for action – adding audio to your game
No game is complete without audio, and fortunately it's relatively simple to integrate in Unity. In this tutorial, we'll demonstrate how to add audio to your Unity project by creating a sound effect that plays whenever a coin is collected. Perform the following steps to add audio:
Click on your
Coin
prefab in the Project window to display its properties in the Inspector window.Click on the Add Component button in the Inspector window and select Audio Source from the Audio menu.
The Audio Source component has several properties that can be set in the Inspector window, as shown in the following screenshot:
The Audio Clip region is where you'll add the sound effect file that you want to play.
The Play On Awake checkbox, which is enabled by default, dictates whether the Audio Source component plays Audio Clip as soon as it's created.
We only want the coin's Audio Clip to play when it's collected, so uncheck the box next to Play On Awake.
Before you add in...