Adding Sound Effects For My Lasers


First I need a set of audio files imported into unity. I have a few already, but id like to give a quick run through on importing it.

All you need to do is simple drag and drop your audio file into your preferred location. Unity supports MPEG,Ogg,Wave,AIFF,MOD,IT,S3M, and XM file types.

We then add a new audio source component to our player prefab and drag and drop our laser sound effects into the audio clip section

We then dive into our player script and declare a reference to our Audio source. I decided to name it ,’PlayerAudio’ to keep things memorable and clear.

The we assign PlayerAudio the attached game objects audio source component by using GetComponent<>(). Now our script knows exactly what component we are trying to access.

I then call the .Play() function in my firing script so that the player will hear the audio clip whenever the player is firing. .Play() will play whatever audio clip that is assigned to the audio sources audio clip. So our player will only be hearing the laser audio clip that is assigned until the audio clip is assigned something else.
I tried to experiment a bit to make the audio a bit different from single to triple shot by changing the volume. Its slightly distinguishable, but ill eventually play different audio for the two firing modes in the future.