Unity is a wonderful program, that allows people with very different backgrounds and specialization to contribute to the building of a game. And building a game indeed does require a lot of different skills, which I as a software developer don’t necessarily possess:
- Storytelling, designing a fictional world, characters, plot line, interactions.
- Level building, ensuring levels are compelling and fun to explore.
- Game design, ensuring the game is mechanically challenging, balanced, and fun to play.
- Sound design, because sound and music does so much for atmosphere.
- Graphic design, creating all those buildings, chairs, plants, skeletons, etc that the player has to look at.
- And yes, also software development, to make sure that things behave as intended.
Building a game by yourself means you need to have at least some superficial knowledge of all these aspects. Thankfully, Unity also provides an Asset Store, where people that are working solo and have different specializations can offer their work for sale. This means I get to buy asset packs containing for instance a whole lot of 3D models of walls and floors and furniture, that I can use to build my level.
This week I spent some time looking at the in-game music. As anyone will realize from watching movies, background music is very important in setting the atmosphere, even if you’re not actively aware of it. It is the same in games, where ideally you’d want the music to shift with the action. Only, in a game you want music to react to what’s happening in the game in real-time, so you can not just compose a piece of music that shifts at predefined moments and play that in the background.
Enter Unity’s Audio Mixer, which allows you to fade audio tracks in and out, much like a real mixer does. Except this one can be controlled from code, so that if specific events happen in-game, we can fade in one track and fade out another.
To be able to fade tracks in and out, without the transition being very noticeable, they need to be essentially from the same piece of music, and be perfectly in sync. Fortunately, I was able to download some music from the Asset Store, that was split up perfectly. They entire piece looks like this:
The track is made up of four parts, which are provided as separate tracks. Each of these separate tracks can be looped (there’s no noticeable transition when the track ends and starts playing from the start). Also, all separate tracks are of the exact same length. This means that if we just start playing all four tracks when the game starts, they will stay in sync forever. Switching from one track to another is a simple matter of fading in the track we want to hear, and muting the track that was already playing.
Suddenly the boss fight at the end of the first level feels that much more epic!