In the last section of this chapter, we will introduce another layer of audio with background or theme music. This is an often overlooked layer that can really set the mood of the game or during the progression of a game. In later chapters of this book where we cover adaptive music we will get into detailed examples of altering music during gameplay. For now though, we are going to look at a simple use of scripting to set the looping behavior of some background music we want to use for our scene. Follow the instructions here to add background music to the scene:
- Open up Unity to the
Viking Village
scene as we last left it. Create an emptyGameObject
in the scene and rename itBackgroundMusic
. - Locate the
viking_music
audio clip in theProject
window. Drag the clip onto the newBackgroundMusic
object in theHierarchy
window. This will automatically add an audio source component with the audio clip set. - Locate the
MusicLooper
script in theProject
window. Drag the script onto...