


We'll determine the song timing, first in seconds, then in beats. With these values, we can now track the location of the song in real time as the game updates. You'll also need to manually enter the BPM of the music you're adding to the Audio Source. If you create an empty GameObject with this script attached, and add an Audio Source with a song and start the program, you can see the script will update with the time when the song started, but not much else will happen. Calculate the number of seconds in each beatĭspSongTime = (float)AudioSettings.dspTime Load the AudioSource attached to the Conductor GameObject When the scene starts, we need to do a few calculations to determine some of the variables, and also record, for reference, the time when the audio began. an AudioSource attached to this GameObject that will play the music. How many seconds have passed since the song started The number of seconds for each song beat This is determined by the song you're trying to sync up to To track the song, we'll need a few variables: With it, we'll track the song position, and control any other synced actions. The Conductor class is the main song managing class that the rest of our rhythm game will be built on. My code derives heavily from both his article and Boots-Cut. You can take a look at his post for a quick guide to music syncing in Unity, but I'll be going over the core of what he outlines and more. Yu covered the core of syncing audio timing to the game engine in Unity, and made the source code for Boots-Cut available, which helped immensely in getting this project off the ground. In this article I'll cover a few of the most useful coding techniques I learned in creating these games that were either not covered somewhere else, or I thought could be covered in more detail.įirstly, I owe a huge debt of gratitude to Yu Chao's blog post ' Music Syncing in Rhythm Games'. I put some work into a few rhythm-based prototypes in Unity, ultimately devoting a month to creating Atomic Beats, a short rhythm/puzzle game. Today I'm always on the lookout for new takes on the genre, and with entries like Crypt of the Necrodancer or, there's still a lot that can be done in rhythm gaming. I've been playing rhythm games since high school, when I frequented the DDR machine at my local arcade. So, you want to make a rhythm game or you tried to make one, but the game elemtns and the music quickly became out of sync, and now you're not sure what to do.
