How to Play Sound Effects in Unity

Create an “Empty Game Object” and call it “Audio_Manager”. Use Add Component” to add the “Audio Source” component. Create a C# script and name it “ Play Laser Sound”. Add the C# script to the “Audio Manager” game object (“Drag and Drop” on to the “Audio_Manager”).

Open the “ Play Laser Sound” C# script and create a private Serialized Field variable of type AudioClip and call it “_laserSoundClip”.

Create a second private variable of type “AudioSource” and call it “_audioSource

This creates a slot (Laser Sound Clip) in the Inspector where we will “Drag and Drop” our sound clip.

Make sure the “Play on Awake” and “Loop” boxes are unchecked in the “Audio Source” component.

Now let's add the code required to play our laser sound.

When we start our game “void Start” function will make a call to PlayLaserSoundClip() and we will hear the laser sound one time. That’s all there is to play a sound clip from within a C# script…Until next time…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store