Home
Username:
Password:
Introduction to Game Development Using Unity 3D Tutorials

Audio / Adding Audio Clips




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

Adding audio files or special effects in Unity is extremely easy to accomplish. If you open up the Project files that come with this course, in the folder Audio, you'll find a file called Grenade. Now, drag this MP3 file on top of the audio in Unity and it will import and show you the WAV form of both of the left and right channel and of course, only one when it's a mono file. Now by default, there's a couple of settings checked here. Of course, Compression is disabled because this is an MP3 file and it's already very much compressed. But if you for example, use WAV files or OGG's, then compression is off and you can check what kind of compression you want. This also goes for AIFF files. Now, 3D sound is something that you wanna have checked on, in case when it comes to sound effects- and not from music though, but for sound effects, because it basically uses this sound in the 3D world as a 3D sound. And that, is picked up by the audio listener. If you open up the camera that's attached to the player Prefab, you will notice that an audio listener is connected to it. If I would duplicate this camera and I would have 2 audio listeners, Unity would give me an error saying, there's 2 audio listeners in this scene- because you only need 1. Now, the audio listener is attached to the camera because we want to hear sound relative to the camera. So for example, if something is exploding towards the right, then we want to hear sound towards the right, as well as for example the left. So that's what 3D sound does. And of course, it's also louder or quieter when you're closer or further away. Now, there's a couple of other settings. It says -Force to mono- and this will force the stereo to a mono file. And then of course, you can also set it to -Decompress on Load-, because when your game loads you could decompress it so that the file size is smaller when you ship it, but you have more frequencies to play with when as soon as the game starts. The of course, there's a Compression in kilobyte per second. And then that's it for the settings. You can preview the audio by clicking the play button. And of course, you can loop that as well. Now, let's attach this to our prefab here. You might think we want to attach it to the grenade, but if you attach to grenade, you have to do more script to get it done. What's easier is just to attach it to the explosion. And as soon as the explosion is created, it will play the grenade sound. So let's open up our -exp- for explosion and just drag this out on top of it. And that's all we need to so. Now, it gives us a couple more options here. Play on Awake means that as soon as it's created, the sound will play. And this is in this case what we want. The Volume of this file is 1 and if you think that's a little too loud, compare it with the others. You can tweak that down a little bit. But I'd highly recommend to do that in your audio editing programs more than I would do that in Unity, although you can. Pitch is an interesting one. For example, if you have footstep sounds, you don't want to have the same footstep play the whole time. But you only need one file. You just slightly change the pitch and then it sounds like a totally different footstep. Then you have a Minimum Volume and a Maximum Volume. And of course, the Rolloff factor of your audio. You can also set it to Loop, so that it will play in multiple times. But in this case, it's an explosion, so we don't want the explosion to loop. Now, if I run my game and I pick up the crates really quickly without trying to get shot by the Turret and I throw the grenade and you will see, that it now plays the sound and it has a little audio symbol that goes away as soon as the sound is done playing. Now, if I throw the grenade and if it's towards the right of the screen, you will hear it in the right speaker and it it's towards the left of the screen, you will hear this in your left speaker. And I just fell off the platform, but that's OK. OK, so that is how sounds work. Of course, there's also the option to script it. If I open up the Script file for example, you could make a new variable and call it -myAudioFile-. And then make it of tight -AudioClip-, and this will allow you to drag an audio file on top of this variable in the editor. And if you want to play it, you can simply reference to it using -myAudioFile. Play- and this will play the sound. It also supports -PlayOneShot- and that mans if you only wanna play it once when it's a looping file, it will only play it once. So that'show audio works in a script, very easy. A lot less complicated than I'd thought it would be when I didn't know about it. So, but it's very flexible and very powerful.

Tutorial Information

Course: Introduction to Game Development Using Unity 3D
Author: Efraim Meulenberg
SKU: 34092
ISBN: 1-936334-03-8
Release Date: 2010-02-23
Duration: 5.5 hrs / 75 lessons
Work Files: Yes
Captions: Available on CD and Online University
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available