

Triggering audio

From: Unity 4.3 Essential Training

Video: Triggering audio

Triggered audio helps reinforce the immersion in our game environment. There's my collider.

Triggering audio

Triggered audio helps reinforce the immersion in our game environment. Theres a mantra, especially in sound editing, see a sound, hear a sound. What that means is we see something we expect to make a sound, then we should hear the sound that goes with it. What I've done so far is to make prefabs for my balcony sound birds and my balcony sound water. I've put them at the corner of the buildings on the balconies. So that, depending on where we are, we hear that water sound when we step outside. For an example, here's balcony sound birds.

And this one's got a max distance on the curve of nine, and minimum distance that's pretty small. So that we're always in the sound zone, essentially, when we step outside. And it fades out to 0 at the end of that range. It's the sound of the lake water and occasionally a bird. It plays on a wake and loops. So that whenever we're on the balcony, we're going to run into this sound. Now get a sound on the doors. What I'm going to do is put the sound actually on the door trigger. So that when we trigger a door to open, we hear this door open sound.

I've put a small JavaScript into the Scripts folder in the Assets folder. Here's what this script does. I'll select it and look in the Inspector. Basically what it says is, I have an audio clip. On Trigger Enter, play that sound once. We can add this to other scripts. And it's very possible you may have quite a few bits of script running on one object. A sound, a check for a key, for example, or a tag, or something similar. But in this case I'm just going to play this one sound when we step into that trigger. Here's how I'll make it work.

I'll pick my door openers. And I've got five of them in here because I've run around and cloned the door animation. So that every balcony has one operable door. I'll start out with Door 11 and press F to focus in. There's my collider. And I'm going to put on this script and a sound source. I'll scroll down, roll up the Activate Trigger and choose Add Component>Audio>Audio Source. In the audio clip then, pulling the Preview window down in the material. I'll go and find that door open sound.

It's the clipped down one, not the full version door open. I'll let it Play on Awake and it's not a looping sound. I'll make its range just a little bit bigger. Taking down that max distance to, we'll say one and a half, and leaving the min distances at 0.75. So it's a very small zone of audio we're in. I'll turn off Play on Awake and I'm ready to get this sound playing. Now what I'll do is add the script onto the box collider to play that sound. I'll drag my door open sound over, and then I can go choose that particular audio clip.

When I run into the collider, it will trigger that sound and the door will open as well. Play my game. Run over to the door. Trigger it to open and I hear the door and then I'm into the water. Its very common to get previews together of actions in a game and hand off to an audio person. For example, if you're working in a character, get a preview of that character moving, running or whatever the action are, over to your audio person. So they can start to get sound together to match that character. Then, when you trigger that particular animation, trigger the sound as well.

I'll add this same script and sound onto my other door opening box colliders. And that way, whenever I go up to a door, I hear that door open. The weather stripping scraping against the brick patio, for example. And it reinforces what I'm seeing.

Show transcript

This video is part of

Image for Unity 4.3 Essential Training
Unity 4.3 Essential Training

78 video lessons · 14477 viewers

Adam Crespi

Expand all | Collapse all
  1. 2m 57s
    1. Welcome
    2. What you should know before watching this course
    3. Using the exercise files
      1m 24s
  2. 21m 21s
    1. Designing the game
      4m 39s
    2. Setting the project
      4m 9s
    3. Exploring the Hierarchy, Scene, and Inspector windows
      5m 45s
    4. Creating and transforming objects
      6m 48s
  3. 21m 34s
    1. Organizing the Assets window
      2m 55s
    2. Exporting objects from 3D modeling programs
      8m 33s
    3. Importing and configuring models and textures
      4m 54s
    4. Setting properties for models and textures in the Inspector
      5m 12s
  4. 29m 8s
    1. Introducing the game environment
      4m 27s
    2. Placing the player controller
      4m 29s
    3. Publishing project settings
      5m 32s
    4. Adding sky and fog
      8m 17s
    5. Fine-tuning the First Person Controller
      6m 23s
  5. 57m 25s
    1. Creating the terrain geometry
      3m 29s
    2. Forming the topography
      9m 54s
    3. Painting the terrain textures
      7m 9s
    4. Painting trees and forests
      10m 55s
    5. Painting grass, shrubs, and 3D geometry
      9m 38s
    6. Painting detail meshes
      8m 46s
    7. Adjusting terrain settings
      7m 34s
  6. 39m 45s
    1. Creating materials and assigning shaders
      8m 56s
    2. Handling multiple materials
      7m 13s
    3. Adding textures to a material
      3m 57s
    4. Manipulating textures
      5m 20s
    5. Adding reflections to materials
      8m 1s
    6. Creating lit materials
      6m 18s
  7. 47m 12s
    1. Creating GameObjects
      5m 2s
    2. Understanding components
      6m 15s
    3. Using colliders for barriers
      6m 22s
    4. Using colliders for triggers
      8m 1s
    5. Exploring physics
      8m 22s
    6. Working with Physic materials
      5m 3s
    7. Adding joints to rigid bodies
      8m 7s
  8. 20m 33s
    1. Setting up prefabs for animation and batching
      5m 8s
    2. Animating an object
      6m 32s
    3. Adjusting timing in an animation
      3m 50s
    4. Animating transparency and lights
      5m 3s
  9. 11m 58s
    1. Importing skinned meshes
      4m 51s
    2. Separating animations into clips and states
      3m 14s
    3. Creating transitions between states
      3m 53s
  10. 30m 22s
    1. Customizing ambient light
      2m 59s
    2. Creating the sun using a directional light
      5m 49s
    3. Using layers and tags for lighting
      3m 32s
    4. Adding spot and point lights
      4m 25s
    5. Using point lights for fill
      4m 30s
    6. Adding and fine-tuning shadows
      5m 10s
    7. Creating lighting effects with cookies
      3m 57s
  11. 9m 15s
    1. Adding scripts to GameObjects
      2m 42s
    2. Using correct script syntax
      6m 33s
  12. 23m 7s
    1. Setting up a 2D project
      3m 13s
    2. Importing sprites
      2m 30s
    3. Slicing in the Sprite Editor
      3m 6s
    4. Layering sprites and setting the sorting order
      5m 12s
    5. Creating 2D colliders
      3m 12s
    6. Adding 2D physics
      2m 25s
    7. Animating 2D elements
      3m 29s
  13. 30m 25s
    1. Creating light shafts and sunbeams
      5m 20s
    2. Using ambient occlusion to add gravity
      4m 37s
    3. Adding depth of field
      8m 40s
    4. Applying motion blur
      5m 46s
    5. Tuning color for mood
      6m 2s
  14. 38m 16s
    1. Exploring water effects
      7m 36s
    2. Working with wind zones
      2m 8s
    3. Using an audio source
      4m 3s
    4. Creating a sound zone
      5m 59s
    5. Triggering audio
      3m 37s
    6. Adding audio effects
      3m 13s
    7. Creating particle systems
      2m 26s
    8. Adjusting particle systems
      9m 14s
  15. 25m 23s
    1. Setting up occlusion culling
      5m 52s
    2. Enabling batching to reduce draw calls
      3m 28s
    3. Testing in the game window using statistics
      4m 27s
    4. Building a development build and debugging
      6m 0s
    5. Building the executable
      5m 36s
  16. 49s
    1. Next steps

Start learning today


Become a member
Share a link to this course

What are exercise files?


Can I take this course without the exercise files?


Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.


Exercise files

Exercise files video

How to use exercise files.



Join now Already a member? Log in



Mark all as unwatched Cancel


You have completed Unity 4.3 Essential Training.


Become a member to add this course to a playlist


Get started

Already a member ?

Become a member to like this course.


Get started

Already a member?

Exercise files


Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.


Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched


Control your viewing experience


Interactive transcripts


Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.



Thanks for signing up.

We’ll send you a confirmation email shortly.






submit Lightbox submit clicked
Terms and conditions of use

Review and accept our updated terms of service.