As I am intending on making my game into a rhythm game, where asteroids come in on a beat, I need to ensure that the game is synced up perfectly with the music. After speaking with Maddi, our technician, I found that the best way to do this would be to fix the frame rate of the game. In doing this, I can ensure that the music plays alongside the game, beginning at the start of a second, and the game will spawn asteroids in specific frames which would be at every half second or quarter second etc; exactly when asteroids should spawn will depend on playtesting, but it will be determined in easy to measure amounts such as multiples of a half second, so that it is easy to sync up to a specific frame and therefore the musical beat.
The musical loops, therefore, must be discrete full seconds long, rather than one and a half or third etc, so that they cannot fall out of sync with the game.
When researching how to adjust the frame rate, I found that it is relatively easy to fix it using a single line of code. The line is below:
Application.targetFrameRate = fps;
// Where fps is a variable storing the frame rate that the game should have
This code should be put in the Start() function of a game object. I intend to create a new empty game object, called Setup, that I will put this code in; other important code for setting up the scene can also be put here.
When limiting the frame rate, I plan to set the target to 30 frames per second. This allows for a smooth experience for a mobile device, whilst not being too demanding. Initially I wanted to go for 60fps, as the gameplay would be smoother and this is the minimum standard for most games, however, on a mobile device this would be the refresh rate of the device. Having the frame rate so high on a mobile device would cause the battery to drain quickly and even cause the device to heat up faster; this is explained in the Unity documentation found at https://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html.