Adding Sound Effects For My Lasers

PieceofPhie
2 min readApr 10, 2021

Photo by Sašo Tušar on Unsplash

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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

PieceofPhie
PieceofPhie

Written by PieceofPhie

Unity Developer Based out of California

No responses yet