How to do it...

To create a music-loop manager, do the following:

  1. Create a new Unity 3D project and import the provided sound clip files.
  2. Create four GameObjects in the scene containing an AudioSource component linked to different AudioClip loops from the 140 bpm files provided. This can be done in a single step by dragging the music clip from the Project panel into either the Hierarchy or Scene panels.
  1. In the Inspector, uncheck the Play On Awake parameter for all four AudioSource components (so they don't start playing until we tell them to).
  2. Add a new empty GameObject named musicScheduler to the scene.
  3. Create a C# script class, LoopScheduler, in a new folder, _Scripts, containing the following code, and add an instance as a scripted ...

Get Unity 2018 Cookbook - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.