The Effect of Crossfading Soundtrack
|
This has been a cool addition to the game! In the human realm: In the spirit realm: I wish I could’ve done more before uploading them, and I most probably will. I put these soundtracks into each of their own audio source in a game object on the scene, and assigned them to a script. I made sure the spirit version was at 0 volume, since the player would begin playing in the human realm, not the spirit realm. Now I had to make these two tracks crossfade when the player switches realms. The script I assigned the audio sources to is named SoundManager (more appropriately named as AudioManager) and it manages the crossfade effect as well as playing sounds. A coroutine function that creates the crossfade effect receives different parameters depending on what realm the player is in. A coroutine, as explained in a previous post, executes a code that runs alongside the main one, so the program doesn’t have to wait until that code has fully exectued. Before lowering and raising any volumes, a float is instantiated with a value of 0f. It acts as a counter (timeCounter). When timeCounter is similar to 1f, the coroutine proceeds to assigning a couple of values. It first of all makes m_currentRealm equal to LevelData.m_spirit so the SoundManager is updated on where the player is and then it makes the boolean value m_changing go false again. That’s what is being done when a crossfade effect occurs. I did not come up with this by myself, and searched around the web in how to create the effect. Nonetheless, I’m quite satisfied to have achieved making the soundtrack dynamic and responsive in this kind of way and it’ll surely make the game more immersive for the player! |