Implementing 2D stereo audio
We'll begin by implementing the simplest form of game audio: two-dimensional stereophonic audio. We'll start with menu sound effects and then move onto music and classic ambient soundscapes.
The first thing we need to do is import some audio files into the project. Find the ButtonClick.wav
and the ButtonHover.wav
files included with this chapter and drag them into a new folder in your Project window called Audio
. You'll know that they're valid audio files from their yellow waveform icon:
Note
Files with the .wav
extension are one of the many supported audio file types in Unity. You can also import .mp3
, .ogg
, .aif
, .mod
, .it
, .s3m
, and .xm
.
Next, we'll create a script that we can use to play these sounds when either of the buttons on the main menu are selected.
Playing a sound when a button is clicked on
Find the MenuCanvas object in your hierarchy and attach a new script named MenuSounds
. Since both our START and QUIT buttons will make sounds, we're putting this...