Game Development Reference
In-Depth Information
Once the intro clip is through playing, toggle the introMusicIsPlaying
boolean variable to false .
5.
(6) if (!introMusicIsPlaying && !looping)
If the intro music is not playing, and looping is still set to false , then it's time
to switch audio clips.
6.
(7) LoopBackgroundMusic();
Call the LoopBackgroundMusic() function, which you will write next.
7.
(8) if(audio.isPlaying == true) {
audio.Stop();
}
It is a good practice when changing audio clips to call the audio.Stop()
function before changing out the audio clip.
8.
(9) audio.clip = musicLoop;
Switch the current audio clip to the audio clip referenced by musicLoop .
9.
(10) audio.loop = enabled;
10.
Enable the Loop property of the Audio Source.
(11) audio.Play();
11.
Play the new audio clip.
In the Unity editor, assign the “Loop 16 - 145 bpm - loop” audio clip by dragging and dropping it into
the Music Loop property field of the BackgroundMusic script component of the Audio game object.
Save and playtest. Now the intro audio clip rolls seamlessly into the loop audio clip, which in turn
loops for the duration.
Something isn't right here, however: as the player character progresses farther along the obstacle
course, the music fades. This is because the audio clips' initial import settings are for 3D. In the
Project panel, open the Assets ➤ Free Pack ➤ Metal Loop Pack, and select each audio clip to
uncheck the 3D Sound property in the Inspector. If an Unapplied Import Settings dialog box appears,
choose Apply. Save the scene, playtest, and now the background music plays continuously and
uniformly, regardless of the player character's position along the obstacle course.
Event-Triggered Sound
One method to play a short clip in response to gameplay is with a trigger.
The Free Pack folder has a Fantasy Victory (free) audio clip. The player's successfully dodging the
enemy drone and making it to the final platform of the elevated track marks successful completion of
the obstacle course, so you'll play this audio clip when the player character makes it this far.
 
Search WWH ::




Custom Search