There are two different types of Audio that will be readily available to you – Footsteps and locative audio.
Spacially located audio / 2d audio
Since Unity 3d works like a real 3d environment, audio in Unity can be specially located. This means that you set the 3d position of Audio Source, and when your character nears this position, the audio gets louder. However, you can also have your audio be “2d”, which just means you will always hear it, no matter where you are. This is a setting in the component, which is explained below.
How to do it:
- Import an audio file into your project
2. Create an Audio Source
3. In the Audio Source, set the AudioClip to be the file that you just imported
4. Change the position of the Audio Source to be wherever you want it to play.
5. Change the other settings in the Audio Source! If you want it to be spacially located, change the “Spacial Blend” slider to be towards the 3d end. If you want it to just play anywhere no matter where your character is, set it closer to “2d.” If it’s spacially located, you’ll want to edit the 3D sound settings, especially the Min and Max distance. See the documentation for more information about what each setting does.
Footsteps
The first person controller asset that we’re using has a really neat footsteps feature, which means you can provide different audio files for it to shuffle through when you are walking on different surfaces with different physics materials. This means that when you walk on a 3d object with a Grass physics material applied to it, you can play grass sounds, but when you’re walking on a 3d object with a Concrete physics material, it’ll play concrete sounds instead. The component is called Audio/SFX Setup under the FirstPersonController game object in our template project!