Displaying a target goal in the HUD

First, we need to create a variable that will establish how many targets we are asking the player to destroy in order to achieve a win. Open up the FirstPersonCharacter Blueprint and create a new variable called Target Goal. Make it an Integer variable type, ensure Instance Editable is checked, and then set its default value to 2 for now.

Now that we have created a Target Goal variable, we should display this information to the player. Open the HUD Blueprint widget we created under our UI folder. From the Designer view, find the Hierarchy panel. Drag two more Text objects from the Palette panel onto the Goal Tracker object in the Hierarchy panel. For the first text object, change the Text field to  / , (including the spaces before and after the slash). For the second text object, change the name to Target Goal, find the Text field, and enter 0. You might have to adjust the size of the Goal Tracker object and click the button next to it to create a new binding.

Now, looking at the Graph view, select the new Get Target Goal Text 0 Function. Similar to the other HUD bindings we created in Chapter 7, Creating Screen UI Elements, we'll need to take the Target Goal variable from the FirstPersonCharacter Blueprint and return that value in this Function, as shown in the following screenshot:

Create a Get Player Character node and drag its output pin onto a Cast To FirstPersonCharacter node. Drag a wire from the casting node's As First Person Character output pin, and attach it to a Get Target Goal node. Next, drag the Target Goal output pin onto the Return Value input pin of Return Node. Finally, connect the casting node to Get Target Goal Text 0 on the input execution pin, and to Return Node on the output.

Compile, save, and press Play the game. You should see that the target counter increments upward as targets are destroyed. The displayed goal number shown on the right of the target counter does not change. Now, we need to ensure that the player gets feedback when they reach their Target Goal.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset