Hello dear friends. As you know, music and sound effects are very important for a game. In this video we’ll add music and sound effect to the game. Let’s get started. First of all, let's determine the music and sound effects we need. Background music , Death sound effect, Wall touch , Portal In , Portal Out and checkpoint sound effect. How can we find these sound effects? we can buy music from Unity Asset Store or import their free music into your project. you can also find sound effects here.
You can find music and sound effects from different websites. I have annual membership of Artlist website. I can use the music and sound effects here in my project under license. You can find many sound effects on this website. Anyway, after a little research, I found the music and effects I wanted and downloaded it. I renamed this sounds, and moved its to an
empty folder named audios. Open Unity. Drag and drop the folder to assets panel. let's look at the sounds. Background music. you ca
n listen by click the play button here. Checkpoint sound effect , Death , Portal In, Portal Out and wall touch sound effect. Let's include these sounds in the game. I'm going to create an empty
object named Audio Manager. then I will create a script named Audio Manager. Open the script. I wanna create a very simple script. we play a music or sound effect using the Audio Source component and we listen to it thanks to the audio listener component. Audio Listener component is included in the cam
era object by default, if not, you can add it. i'm gonna use two different Audio Source to control music and sound effects separately. I will create Audio Clip variable to keep the music and sound effects. Duplicate. Save the script. And go back to unity. I'm gonna add 2 Audio Source . One for music and the other for sound effects. But in this way, Audio sources can be confused with each other. so I will remove the audio sources then I'll add an empty object to
the audio manager named music. A
dd Audio Source. Duplicate. Rename it to SFX. drag and drop the music to here, and SFX to here. Then drag and drop the Audio clips to their slots. Go back to the script. I want background music to
start play when the game starts. Let’s test it. Start the game. As you hear, the background music plays when the game starts. Music is Ready. let's add sound effects to the game. I will create a new method called PlaySFX to play sound effects. I created this method as public, because I wanna access
it from other scripts. This method takes Audio Clip as a parameter. so, using this function, we can play the sound effect we want. now let's play the sound effects from the necessary places. When the player dies and touches the wall, the particle plays. so I can call death and wall touch sound effect from particle controller script. Open particler controller script. I need to access Audio Manager
Script in object Audio Manager. To easily access the audio Manager object from anywhere, I will gi
ve it a tag. Create a tag named Audio. Change the tag as Audio. using an object's tag we can easily access it and its components. let's play wall touch sound effect in here. I will play the same sound effect when the player falls to the ground. and when the player dies I will play the death sound effect. Save the change. Open checkpoint script. I will do the same steps here. I will play the checkpoint sound effect when the player touches the Checkpoint object. Open portal controller script. I
will play the "portal In" sound effect when the player enter the portal, And I will play the "portal Out" sound effect when the player exit the portal. Save the script and go back to unity. Start the game. Nice ! Let's turn the music down a bit. I will activate the loop to start again when the music is over. In the next video we will learn how to use the Audio Mixer ? and adjusting the volume on the interface. I hope the video was useful for you. Thanks for watching. See you in the next video.
Comments