Adding audio

This is getting pretty exciting! We now have a spinning world to augment our reality. Let's add some juice by playing some background music while it spins.

Choose an MP3 file of your choice. We decided to use a free version of Laurie London singing He's got the whole world in his hands (http://www.bulkmp3.co/song/Laurie-London-He-S-Got-The-Whole-World-In-His-Hands-1958.html). The file is included with the downloads for this book. Alternatively, maybe you'd prefer a choice of classical music, or David Bowie's Starman:

  1. In the Project window, create a folder named Assets/Audio and import (drag and drop) the MP3 file into it.
  2. In Hierarchy, create an empty object at root and name it BackgroundMusic (reset its Transform, if necessary).
  3. Go to Add Component | Audio | Audio Source.
  4. Now, drag the MP3 audio clip from the Project window to the AudioClip slot of Audio Source.
  5. Check Play on Awake and Loop because we want it to start playing when the app loads and loop back to the beginning after it plays through.

OK! Press Play and enjoy your app. Then, save the scene and the project. The Audio Source component we just defined is shown in the following screenshot:

If the music gets annoying, you can disable audio in the editor's Play mode in the Game window using Mute Audio. Alternatively, you can temporarily disable it altogether by unchecking the BackgroundMusic object (upper-left corner of Inspector) or disable its Audio Source component (just remember to turn it back on before you build).
..................Content has been hidden....................

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