Applying and adjusting level music
In this section, we are going to look at adding background music to our game levels. We will also be updating our scripts so that our music volume changes at different points of the game.
In the following sections, we are going to do the following:
- Add music to each level.
- When the player completes the level, make the music fade out.
- If the player dies, make the music instantly stop.
- Ensure music does not play in other scenes, only level scenes.
So, let's make a start and add our game music to the level1
scene.
Updating our GameManager prefab
In this section, we are going to update the GameManager
game object so that it holds a new game object (called LevelMusic
) as a child in the Hierarchy window. We will then assign LevelMusic's AudioSource
component and an MP3 fileto play. This kind of setup is ideal for a simple game; otherwise, we potentially run the risk of adding another manager, which is only suitable...