11 Playing audio: Sound effects and music

 

This chapter covers

  • Importing and playing audio clips for various sound effects
  • Using 2D sounds for the UI and 3D sounds in the scene
  • Modulating the volume of all sounds when they play
  • Playing background music while the game is being played
  • Fading in and out between different background tunes

Although graphics get most of the attention when it comes to content in video games, audio is crucial too. Most games play background music and have sound effects. Accordingly, Unity has audio functionality so that you can put sound effects and music into your games. Unity can import and play a variety of audio file formats, adjust the volume of sounds, and even handle sounds playing from a specific position within the scene.

NOTE

Audio is handled the same way for both 2D and 3D games. Although the sample project in this chapter is a 3D game, everything we’ll do applies to 2D games as well.

11.1 Importing sound effects

 
 
 
 

11.1.1 Supported file formats

 
 
 
 

11.1.2 Importing audio files

 
 
 

11.2 Playing sound effects

 
 
 

11.2.1 Explaining what’s involved: Audio clip vs. source vs. listener

 
 
 
 

11.2.2 Assigning a looping sound

 
 

11.2.3 Triggering sound effects from code

 
 
 

11.3 Using the audio control interface

 
 

11.3.1 Setting up the central AudioManager

 
 

11.3.2 Volume control UI

 
 

11.3.3 Playing UI sounds

 
 

11.4 Adding background music

 
 

11.4.1 Playing music loops

 
 
 

11.4.2 Controlling music volume separately

 
 
 
 

11.4.3 Fading between songs

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest