Time for action – add the most important part of any space shooter
We're almost ready to close the book on the main functionality of our space shooter game. We can fire bullets and explodify enemy ships. Although it may well defy the laws of physics, a satisfying fiery explosion occurs in the oxygen-free vacuum of space. But there's just something... missing, yes?
Numerous studies have been conducted to determine the most scientifically accurate sound for a neon-green irradiated bullet being fired through space, and the results have settled unanimously on the onomatopoeic "pew". Luckily, we have just such a sound effect in our Assets
folder, so let's get it going.
At the top of the HeroShip Script, declare a variable to hold the "pew" sound effect:
var pew:AudioClip;
In the left-mouse button firing section of the code, play the "pew" sound effect:
if(Input.GetMouseButtonDown(0)){ audio.PlayOneShot(pew);
Save and close the script.
Find the "pew" sound effect in the Project panel.
In...