Unity audio basics

Unity supports several audio effects, including the Duck Volume Audio Effect, which allows us to manipulate an audio signal's volume.

The term duck refers to making the audio signal quieter.

We can use a variety of audio formats in Unity. You can see the four formats listed here:

  • Audio Interchange File Format (AIFF
  • MP3
  • Ogg Vorbis (OGG)
  • WAV

If you have audio assets that are in a file format different from these four, you can probably use a free audio conversion tool to change the file format.

When we import an audio file into a Unity game, the file becomes an audio clip. Audio clips can also be created from within Unity by using your computer's microphone. You can even create audio clips via scripts during your game.

In Unity, audio sources are attached to objects. These audio sources emit, or play, sound and audio listener components do receive the sound emitted by audio sources. You can think of audio listeners as the player's ears inside the game world, hearing what's near them. Usually, one audio listener component is attached to the main camera so that the sounds it picks up on align well with what is displayed in the game view. Listeners are also attached to objects. Let's look at an example to see how a GameObject, an audio source, and listeners are related.

Let's say we are creating a zoo simulation and are working on the bovine section. There is a holding area for cows. Cows are generally quiet, but might be noisy eaters. The cow would be our GameObject and it would emit a chewing audio clip. The audio clip's RAW file (that is, chewing.aiff) would be identified as an audio source component attached to the cow GameObject. Now, let's say there is a farmer character. We can attach a listener to the farmer, which is also an object. That listener is a script that performs certain actions if it hears the sound from the cow. Perhaps, if the listener picks up the chewing sound, they will know that more hay is needed.

The following diagram illustrates the relationships between the various components:

You will learn how to use these components later in this chapter.

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

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