In this tutorial we’ll add music and connect our game scenes.
We’ll set up:
- music clips in the editor
- add music and scene connections to our game scenes
Let’s get to it!
Music #
We’ll start with setting up the music.
Open the editor and navigate to Game > Music, we’ll change the Default music and add additional music.
You can find the used audio clips in Assets/Tutorial Assets/NinjaAdventure/Musics/.
0: Town #
- Name
Set to Town. - Audio Clip
Select 4 – Village. - Loop Clip
Enable this setting.
1: Forest #
- Name
Set to Forest. - Audio Clip
Select 13 – Mystical. - Loop Clip
Enable this setting.
2: Battle #
- Name
Set to Battle. - Audio Clip
Select 17 – Fight. - Loop Clip
Enable this setting.
3: Victory #
- Name
Set to Victory. - Audio Clip
Select 3 – Revelation. - Loop Clip
Enable this setting.
4: Lost #
- Name
Set to Lost. - Audio Clip
Select 7 – Sad Theme. - Loop Clip
Enable this setting.
Save Changes #
That’s it for the setup.
Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.
Town Scene Setup #
Next, we’ll set up the music and scene connections of our 3 game scenes – Town, Forest and Deep Forest. The rest of the scenes are used in a different way (for the start menu and battle scenes).
We’ll start with the Town, which should still be open from the last tutorial, otherwise you’ll find it at Assets/Scenes/.
We’ll add a Music Player and Scene Changer (to connect to the Forest scene).
Add Music Player #
Music Players are used to, well, play music. The default setup will automatically play it when the level is loaded, but you can change that in the component’s Start Settings (we’ll keep the default setup, though).
Use the scene hierarchy context menu (Makinom > Music Player) or the scene wizard (Create Object > Music Player) to create a Music Player in the scene.
- Play Type
Select Fade To. - Music Clip
Select Town. - Fade Time
Set to 1. - Interpolation
Select Linear.
It also doesn’t matter where you place the music player.
Save the changes you’ve made in the scene.
Add Scene Changer #
Scene Changers are used to load a new scene and (optionally) spawn the player in it. The default setup will load the new scene when the player walks into the trigger of the game object (and can be changed, like the music player).
Use the scene hierarchy context menu (Makinom > Scene Changer (2D)) or the scene wizard (Create Object > Scene Changer 2D) to create a Scene Changer in the scene.
We’ll change some settings in the inspector of the newly game object.
Transform #
We’ll place a scene changer at the exit of the town to load into the Forest scene.
- Position
Set to X=-20, Y=-1, Z=0.
Scene Changer #
We’ll set the already added Target Scene 0 to change to the Forest scene.
- Target Scene
Set to: Forest - Position Type
Select Spawn Point. - Spawn ID
Select Value > Value. - Value
Set to 0.
With this setup, we’ll spawn the player at spawn point with the spawn ID 0 in the Forest scene.
Circle Colider 2D #
The default setup comes with a Circle Colider (set up as Trigger), but we’ll use a Box Colider 2D instead.
So, remove this component.
Box Colider 2D #
Add a Box Colider 2D component using the Add Component button or the component menu.
- Is Trigger
Enable this setting. - Size
Set to X=1, Y=4.
The finished scene changer should be placed like this.
Forest Scene Setup #
Before opening the Forest scene, select the following game objects in Town scene:
- ORK Game Starter
- Spawn Point 0
- Music Player
- Scene Changer
Copy them to the clipboard (e.g. via CTRL+C on Windows), this’ll make our setup in the next scene a bit shorter.
Now, open the Forest scene (Assets/Scenes/) and paste the copied game objects into the scene.
The ORK Game Starter can be left as it is, we just need it to be able to start playing directly in the scene to quickly test things out if we want.
Spawn Point 0 #
We’ll move the spawn point (spawn ID 0) to the right side of the forest and change it’s rotation on the Z-axis to face the player the other way.
The default rotation of 0 will have the player face to the right side – to face to the left, the rotation needs to be 180.
Transform #
- Position
Set to X=18, Y=-1, Z=0. - Rotation
Set to X=0, Y=0, Z=180.
Music Player #
We’ll change the music to use the Forest music.
- Music Clip
Select Forest.
Scene Changer (to Town) #
Like the spawn point, we’ll move the scene changer to the right side of the forest (and update it’s target scene).
Transform #
- Position
Set to X=20, Y=-1, Z=0.
Scene Changer > Target Scene 0 #
- Target Scene
Set to: Town
Scene Changer (to Deep Forest) #
Now, create a duplicate of the Scene Changer and move the new copy to the left side of the forest.
We’ll connect it to the Deep Forest scene.
Transform #
- Position
Set to X=-20, Y=-3.5, Z=0.
Scene Changer > Target Scene 0 #
- Target Scene
Set to: Deep Forest
Box Colider 2D #
We’ll adjust the size to fit the exit.
- Size
Set to X=1, Y=3.
Add Spawn Point #
Next, we’ll add a new spawn point. Creating a new one instead of copying the existing spawn point will automatically set it to use a new, unused Spawn ID.
Use the scene hierarchy context menu to create a new spawn point: Makinom > Spawn Point
The Spawn ID should be set to 1.
Transform #
- Position
Set to X=-18, Y=-3.5, Z=0.
Spawn Point #
- Use Rotation
Enable Z.
Add Camera Border #
Select the Camera Border game object and add a Camera Border component to it using the component menu.
That’s it for the scene, save your changes.
Deep Forest Scene Setup #
Like before, select the following game objects in Forest scene:
- ORK Game Starter
- Spawn Point 0
- Music Player
- Scene Changer (one of them)
Copy them to the clipboard.
Now, open the Deep Forest scene (Assets/Scenes/) and paste the copied game objects into the scene.
This time, ORK Game Starter and Music Player can be left as they are, since it already plays the Forest music.
Spawn Point 0 #
We’ll again adjust it’s position – but the rotation is already what we need (Z=180).
Transform #
- Position
Set to X=18, Y=9.5, Z=0.
Scene Changer (to Forest) #
Adjust the position, target scene and spawn ID (we now spawn at spawn point 1).
Transform #
- Position
Set to X=20, Y=9.5, Z=0.
Scene Changer > Target Scene 0 #
- Target Scene
Set to: Forest - Value (Spawn ID)
Set to 1.
Box Colider 2D #
If you’ve copied the bigger scene changer, adjust the size of the colider.
- Size
Set to X=1, Y=3.
Add Camera Border #
Select the Camera Border game object and add a Camera Border component to it using the component menu.
That’s it for the scene, save your changes.
Battle Forest Scene and Battle Deep Forest Scene Setup #
The setup for the Battle Forest and Battle Deep Forest scene is the same – all we need to do is add a Spawn Point at the center (X=0, Y=0, Z=0).
We’ll later use this to spawn the battle.
Add Spawn Point #
Use the scene hierarchy context menu to create a new spawn point: Makinom > Spawn Point
The Spawn ID should be set to 0.
Transform #
- Position
Set to X=0, Y=0, Z=0.
Start Menu Scene Setup #
And lastly, open the Start Menu scene.
We’ll add a music player to stop whatever music is playing and a game starter (but not set up to start the game).
Add Game Starter #
Use the scene hierarchy context menu to add an ORK Game Starter: ORK Framework > ORK Game Starter
We can keep the default setup – i.e. the Project asset is already selected and Start Game is disabled.
Add Music Player #
Use the scene hierarchy context menu: Makinom > Music Player
- Play Type
Select Stop.
Save the changes you’ve made in the scene.
Testing #
Open the Town, Forest or Deep Forest scene and hit play.
You can now move between scenes and enjoy how the music changes. Though, the scene changes look a bit off, because we’re missing the screen fades without having a UI system set up.
So, next, we’ll set up the UI system!