Lesson 4: Music and SFX

In this lesson, we’re going to add sounds — music and effects — to our game.

Sounds

In your Assets folder, create a new folder called Sounds. Be sure to import your audio files here. Use MP3s or OGGs instead of WAV files to reduce the size of your game. Use Audacity to convert files from WAV to MP3 or OGG if needed.

Check out the website below to find high quality, open source audio files for your game. You MAY NOTuse audio files with copyright protection in your game.

BirdScript.cs

Import a “flapping” sound effect (audio file) to your Sounds folder. Add the audio file to your Bird Prefab as a component. Then add the code below to BirdScript.cs. Add it where it will play every time the mouse is clicked.

1

2

3

//This is a sound effect

AudioSource audio=GetComponent<AudioSource>();

audio.Play();

Background Music

Import background audio (song or effect) that will sound good on a loop. Then attach the song to your game engine in Level_01 and match the settings in the image.

Make sure you “Play on Awake” to get the music to start when the level starts, and make sure you check “Loop” so that the music continues to play for as long as the level is active.