Made With Unity | 2D Space Shooter Part 15: Game Audio
Adding some sound effect can help make our game immersive.
On your Background object add a Audio Source and where it says AudioClip you will put your desire music for the background music, make sure Play On Awake and Loop are checked. Edit the volume and when you play the game the music will start to play.
GAME SOUND EFFECT
Player’s Laser And Power UP Sound Effect
On the Player object, add the Audio Source component and make sure the Play On Awake and Loop are not checked.
On the Player script will add the following variable from the image and on the Start() method we get the Audio Source component
On the ShootingLaser() method we add the next line of code to get the sound effect when we shoot
Create a new method called ActivatePowerUpSoundEffect() will have the code to activate the sound effect we we pickup a PowerUp; then in all 3 script of our PowerUp we called to activate the sound effect.
Back to the Player object, add the effect to there corresponding fields
Explosion Sound Effect
Same as the Player, add a Audio Source component with the same settings to the Asteroid object and the Enemy prefab. Add the following line of code on both the Asteroid script and the Enemy script and called the explosion sound effect when they are about to get destroyed:
Add the sound effect to there fields:
Adding A Escape Feature
Double click on the 2D_Shooter_InputActions map
Add a new Actions and name it Escape with a Action Type of Button
Where it says <No Binding> press the Path and select Escape from the Keyboard and if you like also add a new Binding and add the Start from your Gamepad / Xbox controller
Input Manager Script
On the InputManager script add a new variable and the reference on the Start() method
Create a new public method called EscapeAction()
Open the GameManager script and the the following lines of code on the Update() method.
🎮PART 16 🎮