Making text bindings for the ammo and goal counters

The ammo and goal counters will be represented by texts on the HUD. Follow these steps in order to bind the ammo counter:

  1. Click on the Designer button to return to the canvas interface once more. This time, we want to select the Ammo Left text object in Hierarchy, which can be found under  Weapon Stats.
  2. In the Details panel, find the Bind button next to the Text field and create a new binding, as shown here:

  1. We will follow the same pattern for this binding as we did for health and stamina. In the Get Ammo Left Text 0 graph view that appears, create a Get Player Character node, cast it to the Cast To FirstPersonCharacter node, and then link the As First Person Character pin to get Player Current Ammo.
  1. Finally, attach both the cast node and the Player Current Ammo node to Return Node. You will notice that when you attach the Player Current Ammo output pin to the Return Value input pin, a new ToText (integer) node will be created and linked automatically. This is because Unreal Engine knows that for you to display a numerical value as text on the screen, it first needs to convert the number into a text format that the Widget knows how to display. The conversion node will be hooked up already, so there is no need to make further modifications. The next screenshot shows the nodes that are used in the binding:

  1. The final binding to create is for our Goal Tracker target count. Return to the Designer view and select the Target Count object in Hierarchy, under Goal Tracker. Click on the Bind button next to the Text field in the Display panel. By following the preceding steps, create a Blueprint chain that grabs the player character, casts it to the Cast To FirstPersonCharacter node, and connects the Target Kill Count variable to the casting and return nodes. As with the ammo count, the conversion to a text node will be automatically generated and connected for you. The final result should look like this:

  1. We've now successfully bound all our UI elements to player variables. Now is a good time to compile and save our work. Because of our bindings, the UI will now do its job of responding to Events that occur within our game. However, we still need to create the Events that will trigger changes in the variables we have connected. In the next section, we will modify the player variables based on Actions that the player takes while playing.
..................Content has been hidden....................

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