---
title: "Implement sound effects"
content_type: tutorial
url: "https://learn.unity.com/tutorial/implement-sound-effects?language=en"
language: en
difficulty: beginner
duration_minutes: 30
unity_version:
  - "2020.3"
  - "2020.2"
  - "2020.1"
  - "2019.4"
  - "2019.3"
supported_unity_versions:
  - name: "2020.3"
    url: "https://learn.unity.com/tutorial/implement-sound-effects.md?language=en&version=2020.3"
  - name: "2020.2"
    url: "https://learn.unity.com/tutorial/implement-sound-effects.md?language=en&version=2020.2"
  - name: "2020.1"
    url: "https://learn.unity.com/tutorial/implement-sound-effects.md?language=en&version=2020.1"
  - name: "2019.4"
    url: "https://learn.unity.com/tutorial/implement-sound-effects.md?language=en&version=2019.4"
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/implement-sound-effects.md?language=en&version=2019.3"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/implement-sound-effects.md?language=en"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/implement-sound-effects-jp.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/eumhyang-hyogwa-guhyeon.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/shi-xian-yin-xiao.md?language=zh-cn"
last_updated: "2026-08-04T14:23:32.000Z"
---

# Implement sound effects

Learn to implement static and contact sound effects in Unity and add closed captions for improved accessibility.

In this tutorial, you’ll:

- Implement a static sound effect
- Implement a contact sound effect
- Add closed captions for these sound effects

## 1. Overview

Now that you’ve created a basic interactive VR experience, you can use audio to make it more engaging and immersive. In this tutorial, you’ll add static and contact sound effects to objects in your Prototype Room. You’ll also add closed captions to make your VR experience more inclusive.

## 2. Before you begin

In this tutorial, you’ll use the VR Beginner Unity Project and your VR hardware. Before you begin:

**1.**  Open the VR Beginner Unity Project.

**2.**  Check that your hardware is ready. If you’re using Oculus Link with the Oculus Quest, enable and connect this now through the Oculus app.

## 3. Implementing basic audio sound effects in VR

You can add sound to VR experiences in Unity just like non-VR experiences. Unity can also spatialize the audio (make it sound like the audio source is coming from within a 3D environment). To use Unity’s audio spatializing features, you need to make sure that:

- The Camera GameObject in your Scene has an [Audio Listener component](https://docs.unity3d.com/Manual/class-AudioListener.html&sa=D&ust=1582204767622000&usg=AFQjCNHvNaDANVldGMwG10Tf9tQYGNWsrw), so that Unity can spatialize the sound properly through headphones, based on the position of your VR headset

- Sounds that are part of your VR experience have their Audio Source Spatial Blend set to 3D, to be more immersive in experience


This is already configured by default in Prototype Scenes created using the custom menu in this Unity Project.

## 4. Add a static sound effect to an object

First, let’s add a spatialized looping sound to your Prototype Room — a low hum for the fusebox.

To add the sound to the Fusebox GameObject:

**1.**  In the Hierarchy, select the **Fusebox** GameObject.

**2.**  In the Inspector, select **Add Component.** Search for “Audio Source”, and add this component to the GameObject.

![](https://connect-mediagw.unity.com/h1/20200220/learn/images/2064b442-231f-4bc1-8450-02790c3f076a_6.4_2_addComponent_sound.jpg)

**3.**  In the Project window, go to **Assets** > **VR Beginner** > **Audio**. Find the **SFXDoorHumLoop** audio file.

**4.**  Drag **SFXDoorHumLoop** from the Project window to the Audio Clip property at the top of the Audio Source component.

**5.**  In the Audio Source component, enable **Play On Awake** and **Loop**.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/366a77ed-aa9b-457b-9bb2-ab6878e8b946_6.4.5_EnableSettings.png)


**6.**  Set the **Spatial Blend** slider to 3D (1 in the numerical field).

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/5f575696-2bfe-4e6f-9708-3c952f36169b_6.4.6_SpatialBlend.png)

**7.**  Select the grey arrow to expand the 3D Sound Settings, if it is not already open.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/1114493b-9559-4bd7-9156-c59debf42ec8_6.4.7_ExpandSettings.png)

**8.**  Set the following property values:

- **Volume Rolloff** to **Linear Rolloff**, which means the further you are from the audio source the quieter it will be
- **Min Distance** to **0.2**, which defines the distance at which maximum volume is reached
- **Max Distance** to **4**, which defines the distance where the sound begins to play

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/2a095053-bad8-4117-9ee3-73b64859b3e0_6.4.8_3DSettings.png)


**9.**  Press **Ctrl** + **S** to save your changes.


**10.**  You can now test the sound effect. When you are on the teleporter next to the fusebox you will hear the sound loudly. It will be much more faint if you create a teleporter further away. If you move your head, the audio will change as it would in real life.

## 5. Using closed captions in VR

Close captions are a feature which can improve the inclusivity of your VR experience. This learning project includes an example prototype Closed Caption System, as an indication of how you can implement this in a VR experience.

The prototype Closed Caption System is made of three scripts:

- **CCDatabase**, which associates a given audio clip with one or multiple lines of text and display timings for each line

- **CCSource,** which can be added to an object that has an Audio Source component (like the Fusebox) and enables closed captions for the object

- **CCManager**, which checks for audio sources with closed captions enabled in the Scene and displays the text when the user is in front of the object


These scripts are all located in **Assets** > **VR Beginner** > **Scripts** > **System**.

## 6. Add closed captions for the sound effect

Let’s add closed captions to the Fusebox sound effect:

**1.**  In the Project window, go to the Assets folder. Right-click and select **Create** > **ClosedCaption** > **CCDatabase** to create a new database Asset.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/afe70358-3ed3-4dfa-8942-701bb43f7b11_6.6_1_addCloseCaption_CCDatabase.jpg)

**2.**  Press **F2** and rename the Asset to _TutorialCCDatabase_.



**3.**  Double-click the Asset icon to open the database editor.

![](https://connect-mediagw.unity.com/h1/20200226/learn/images/d708d7d7-ff74-429e-a110-0dac47ef7921_6.6.3_BlankDatabaseEditor.png)

**4.**  In the Project window, go to **Assets** > **VR Beginner** > **Audio**. Drag **SFXDoorLoopHum** from the Project window into the TutorialCCDatabase window. This is the sound effect you added to the Fusebox.

**5.**  Select the new button which appears with the sound effect name.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/0b70808b-7d13-4a46-a293-78c5d0dd67f8_6.6.5_ClipButton.png)

**6.**  Select **New Line** to create a new line of text in the database. Add “\[ Humming \]” to the new **Line** field.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/db0a6bfa-6f00-45e6-8672-6d768e6b4a42_6.6.6_AddLine.png)

**7.**  As the sound effect is more than three seconds long, let’s create another line of text for the closed captions to see what that looks like in the Unity Project. Select **New Line** again and set:

- **Time** to **1.5**
- **Line** to “\[ More humming \]”

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/6a936abb-0d2d-4ea3-a2bd-8c5c812ed812_6.6.7_AddLine2.png)

This means that when the sound has played for 1.5 seconds, the second line of text will be displayed. You can now close the database editor window.


**8.**  In the Hierarchy, select the **CCSystem** GameObject.


**9.** In the Inspector, use the selector button to the right of the **Database** field to select your new TutorialCCDatabase as the database the Closed Captions System reads from.


![](https://connect-mediagw.unity.com/h1/20200227/learn/images/72172862-cb7a-4125-93fd-c66506488116_6.6.8_CCManager.png)

**10.**  Press **Ctrl** + **S** to save your changes.

## 7. Set the Fusebox as a closed caption source

Now that you’ve added closed captions to the sound effect, you need to set the Fusebox GameObject as a source for closed captions in the Scene:

**1.**  In the Hierarchy, select the Fusebox GameObject.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/d9b3ba59-c6f8-4831-be0f-045cf38fd902_6.7.1_SelectFusebox.JPG)

**2.**  In the Inspector, select **Add Component**. Search for and add a **CC Source** component.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/254882af-3950-4c31-bf9a-f643e5b0c8df_6.7.2_AddComponent.jpg)

**3.**  In the Project window, go to **Assets** > **VR Beginner** > **Prefabs** > **System**.

![](https://connect-mediagw.unity.com/h1/20200225/learn/images/25a8280e-153c-4caf-b668-0c662c9550ed_6.7.3_SystemFolder.JPG)

**4.**  Drag the **CCCanvas** Prefab from the Project window to the **Canvas Prefab** field the CC Source component in the Inspector.

[Video](https://connect-mediagw.unity.com/h1/20200225/videos/de061cb0-57f4-4f33-8026-c657ba247877_6.7.4.mp4.mp4)

This canvas defines how the closed captions will appear. If you have more experience with UI development for Unity, you can customize this for your VR experience.

**5.**  You can use the following fields in the CC Source component to make basic adjustments to the caption display:

- Enable **Always Tracked**. This displays an arrow in the center of the user’s view that points to objects with closed captions that are playing. This can indicate critical audio sources for the user, for example those that give gameplay information.

- Set **Max Distance** to **2**. This is the maximum distance at which the caption is displayed. The Fusebox captions will display when you are standing next to it, but will not appear when you’re next to the table.

- Set **Scale** above **1** to increase the default caption size, or below 1 to decrease it.


**6.**  Press **Ctrl** + **S** to save your changes.


**7.**  You can now test the sound effect closed captions. When you stand next to the Fusebox, the caption text should appear, cycling as the sound effect loops. When you move back to the box table, you should not see the closed caption text. If you enabled **Always Tracked**, you should see an arrow indicating the direction of the sound effect.

## 8. Add a contact sound effect to your object

VR Beginner includes a custom system called **SFXPlayer**, which enables scripts to play SFX (special effects) sounds. Prototype Scenes created using the custom menu include this system by default. One feature of this Unity Project is a custom script to set sounds when an interactable object makes contact with another object. For example, this script will play a sound if the grabbable flashlight is dropped onto a table.

To add a contact sound effect to a grabbable object in your Scene:


**1.**  In the Hierarchy, select the interactable item GameObject.


![](https://connect-mediagw.unity.com/h1/20200225/learn/images/9ed62eb3-919d-4a17-af47-a3411590ebe1_6.8.1_InteractableObject.JPG)

**2.**  In the Inspector, select the **Add Component** button.


**3.**  Search for and select the **Contact Sound Player** component. This is a custom component created for this Unity Project.


![](https://connect-mediagw.unity.com/h1/20200225/learn/images/3758d996-6d54-46ec-b05e-2464b1a3ebfa_6.8.3_ContactSOundPlayerComponent.JPG)

**4.**   In the Project window, go to **Assets** > **VR Beginner** > **Audio** and select a sound effect file.  Try one of the four **SFXImpactHeavy** audio clips in the folder.

**5.**  Drag the file from the Project window onto the **Clips** property in the Contact Sound Player component.

[Video](https://connect-mediagw.unity.com/h1/20200225/videos/7fdf0e5d-bf65-415e-b300-90a829b9e205_6.8_5.mp4.mp4)

If you do this with multiple sound effects, the script will select one use randomly when the object makes contact with another. Try adding all four variant **SFXImpactHeavy** audio clips.


**6.**  Select **Ctrl** + **S** to save your changes.


**7.**  You can now test the sound effect in VR. Pick up the interactable object you selected and drop it onto one of the block tables. You should hear one of the sound effects you added to the Contact Sound Player component.

## 9. Challenge: Add closed captions for the contact sound effect

Now that you’ve added a contact sound effect for your object, try adding a closed caption for the effect.

Remember you’ll need to:

- Add the sound effect to the database, and set its caption text and timing(s)
- In the Contact Sound Player component, enable the **Closed Captioned** checkbox
- Test to check that you have implemented the closed caption successfully


If you need more guidance to complete this challenge, review steps six and seven of this tutorial.

## 10. Summary

In this tutorial, you have implemented audio and closed captions to enhance your VR experience. Next, you will learn how to set up the Unity project for UI development.
