Course Content
Unity for Beginners
Unity for Beginners
Sounds in Unity
Importing Audio Assets
First, you need audio assets to use in your Unity project. You can either create your own audio files or find free-to-use audio assets online. Once you have your audio files, you can import them into your Unity project by dragging them into the "Assets" folder in the Unity Editor.
Adding an AudioSource Component
In Unity, the AudioSource
component is used to play sound clips. Here's how you can add it to a GameObject
:
Select the GameObject
to which you want to attach the audio source (e.g., an empty GameObject
or any object you want to emit sound).
In the Inspector window, click on the "Add Component" button.
Type "Audio Source" in the search bar and select "Audio Source" from the dropdown menu.
Setting up the AudioSource
Once you've added the
AudioSource
component to your GameObject
, you can configure it in the Inspector window:
Audio Clip: Assign the audio clip you want to play to the "Audio Clip" field. This is the actual sound file you imported in Step 1.
Volume: Adjust the volume of the audio clip using the "Volume" slider. This controls how loud the sound will be when played.
Loop: Check the "Loop" checkbox if you want the audio clip to repeat continuously.
Spatial Blend: Adjusts how much the audio is affected by 3D spatialization. A value of 0 means the audio is 2D (non-spatial), while a value of 1 means the audio is fully 3D spatialized.
Play On Awake: Check this checkbox if you want the audio clip to start playing automatically when the
GameObject
is activated.
Everything was clear?