2D Shooter: Pew Pew!
Objective: Add pew pew sounds whenever the lasers fire.
Let’s start in the player script and add two variables: One for the audio clip, and another for the audio source component.
Now in the inspector, attach the audio file you want to _laserShot.
Now let’s get the audio source component in the start method.
Now we need to check if the audiosource is null, and if not, to connect the audio clip to it.
We could have the audio file within the Audiosource itself, and that way we would only need to get the component and check its status, but this way we have room to add other clips down the line.
Now to call the sound when the lasers are instantiated.
All you need is that last line of code: “_audioSource.Play();”