Chapter 9. Playing and Manipulating Sounds

In this chapter, we will cover:

  • Matching the audio pitch to the animation speed
  • Simulating acoustic environments with Reverb Zones
  • Preventing an Audio Clip from restarting if it is already playing
  • Waiting for audio to finish playing before auto-destructing an object
  • Adding volume control with Audio Mixers
  • Making a dynamic soundtrack with Snapshots
  • Balancing in-game audio with Ducking

Introduction

Sound is a very important part of the gaming experience. In fact, we can't stress enough how crucial it is to the player's immersion in a virtual environment. Just think of the engine running in your favorite racing game, the distant urban buzz in a simulator game, or the creeping noises in horror games. Think of how these sounds transport you into the game.

The big picture

Before getting on with the recipes, let's step back and have a quick review on how sound works on Unity 5.

Audio files can be embedded into GameObjects through the Audio Source component. Unity supports 3D sounds, which means that the location and distance between the audio sources and Audio Listener matter in the way the sound is perceived in terms of loudness and the left/right balance. This is unless the audio source is specified as 2D sound (which is usually the case for the background soundtrack music).

Although all sound is sent to the scene's Audio Listener (a component that is usually attached to the Main Camera, and that shouldn't be attached simultaneously on more than one object), Unity 5 brings a new player to the audio scene: the Audio Mixer. The Audio mixer radically changes the way in which sound elements can be experienced and worked with. It allows developers to mix and arrange audio pretty much in the same way that musicians and producers do in their Digital Audio Workstations (D.A.W), such as GarageBand or ProTools. It allows you to route audio source clips into specific channels that can have their volumes individually adjusted and processed by customized effects and filters. You can work with multiple Audio Mixers, send a mixer's output to a parent mixer, and save mix preferences as Snapshots. Also, you can access mixer parameters from scripting. The following figure represents the main Unity 5 audio mixing concepts and their relationships:

The big picture

Taking advantage of the new Audio Mixer feature in many example projects, this chapter is filled with recipes that will hopefully help you implement a better and more efficient sound design for your projects, augmenting the player's sense of immersion, transporting him or her into the game environment, and even improving the gameplay.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.156.93