Immersion Starts with Sound

Renato Figueiredo
2 min readDec 9, 2023

Objective: Learn how to add and use an audio system in our game.

We can notice that our Main Camera object has an Audio Listener component, meaning it can pick up sounds. In order for us to manage the sound of our game better, we are going to use an Audio Manager, who is going to be responsible for it.

Creating our Audio Manager object.

Now we are going to create the object who is going to be responsible for our Background music, which is going to be inside our Audio Manager.

Adding our Audio Clip to the object, and making sure that it both plays on Awake and its Looping.

Now, when we start our game, we have a background music.

But this is not the only moment when we need sound in our game, right ? So let’s add the sound of our lasers being shot by our player!

[SerializeField] private AudioClip _laserSound;
private AudioSource _audioSource;
private void Start()
{
_audioSource = GetComponent<AudioSource>();
if (_audioSource == null)
{
Debug.LogError("Audio Source is NULL on the Player");
}
else
{
_audioSource.clip = _laserSoundClip;
}
}
Creating our Audio Source in our player, and attaching our Laser Sound Clip.

All we are doing is creating the Audio Source on our player, assigning it to a variable, making sure the player has a reference of the laser sound clip, and that clips is immediately attached to our Audio Source on Void Start.

We can change the volume if we want, so you can test how loud the laser should be, but with this, all we are doing is assigning the laser sound clip to our player when the game starts. If we wanted, we could change clips to play during our gameplay.

And there you have it, now we have both a background music, and laser sounds coming from our player. Its sounding like a real videogame!

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

No responses yet

Write a response