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



1. Temporarily disable the pause menu

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:

2. Create a HUD loader

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 Mode parameter, 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:

  1. Open the Level1 scene. 
  2. Create a new empty game object called HudLoader
  3. Add a flow machine component to it
  4. Set its source to macro, and its macro to the one we just created
  5. Drag the game object in the Prefabs folder to create a prefab from it

The final inspector should look like this:

3. Add the HUD loader to every scene

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:

Level Change Doors & Keys

Is this article helpful for you?