For adding sounds, the files are included in the Resources
folder for this chapter. There are three files in total, of which two are sounds effects and one is a music file. The sounds effects are to be used in the game.
The punch sound is to be played when whether the enemy or the player gets hit. The block sound is to be played when the player or the enemy blocks the attack. The bgMusic
file is the background music file that is to be played when any scene loads. Drag the Audio
folder into the project.
Now open the MainMenu scene. And drag the bgMusic
file into the scene. Take a look at the Inspector
pane:
The position of the background music doesn't matter, but if you were using the sound for ambience then make sure that you set the location of the sound source.
The Play On Awake
option is checked by default, which is what we want. However, we also want the music to be looped, so make sure to check the Loop
checkbox as well.
If you play the scene, you will hear the sound playing...