In this part, we will load a head-up display (HUD) on top of our game view. This HUD will later be responsible for displaying health, keys, power ups and the pause menu.
The technique we will be using for our HUD is to build it all in a separate scene, and then load that scene on top of the real game scene. This has a few advantages over using a prefab:
- It allows us to use prefabs in the HUD (which we can't do with a prefab-HUD because Unity does not support nested prefabs)
- It allows us to use embed graphs and scene references for our GUI elements, which greatly simplifies the Bolt workflow
The HUD is already included in the tutorial assets under Scenes / HUD.
Because we won't be implementing the logic for the pause menu until the end of the tutorial, we will disable it for now so it doesn't cover our view while playing.
Open the HUD scene, select the PauseMenu object, and make it inactive:
Create a new flow macro called HudLoader. In its graph, we only need these units:
We use the overload for Load Scene that has a Modeparameter, and set the mode to Additive. That will tell Unity to keep the current scene, for example Level1, but also load our HUD scene on top of it.
Lastly, we'll create a simple prefab to run this loader:
- Open the Level1 scene.
- Create a new empty game object called HudLoader
- Add a flow machine component to it
- Set its macro to the one we just created
- Drag the game object in the Prefabs folder to create a prefab from it
The final inspector should look like this:
Open Level2, Level3 and Level4 and drag the new HudLoader prefab into each scene.
If you test your game now, you should see a row of hearts and icons appear in the top right corner when you enter play mode: