A game without sound is like, hmm, this article really
How to Play Sound Effects in Unity
--
Objective: Add sound effects when shooting lasers, blowing up stuff, and collecting powerups
Sounds play a critical role in immersing the player into the game by using music and sound effect. Seeing an asteroid explode so far is pretty cool but to actually hear the explosion as well adds the realism. On top of that, having music playing in the background, sets the mood and if used effective can really movitate the player.
How to add background music
Let’s start by Creating an Empty game object to the game scene called Audio Manager. This will manage all the sounds in the game.
Now let’s first focus on adding background music to the game. Within the AudioManager, Create another Empty game object and call it BackgroundMusic.
Next add an Audio Source component to the BackgroundMusic.
Now find the music file you wish to bring into the game, and drag it into the AudioClip slot. Make sure Loop is checked so the background music continues to loop while the scene is playing. Go ahead start your game to hear the music.
In the Audio Source component, you have a lot of settings you may adjust to make the music sound right.
How to add sound effects
In the section, I am going to add sound effects when I fire off a laser. An Audio Source component is best placed on the Player since the player is firing the laser and that is where the PlayerShoot script component is too. Uncheck Play On Awake so the sound effect sound does not fire off right away.
Next we need a variable in the PlayerShoot script to store a reference to the Audio Source and to store the Audio Clip (laser sound effect).
In the Start method, get the reference to the Audio Source component
In the Fire Method, I have added the code to play the clip when the laser is shot.
Phew Phew Phew! You just going to have to believe me. The game feels sooooo much better with music and sound effects.
If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.