Increasing the targets eliminated counter

Now, we want to increase our targets eliminated counter by 1 every time a target Cylinder is destroyed. Recall that the Blueprint scripting that controlled the destruction of the Cylinder targets was attached to the CylinderTarget_Blueprint Blueprint. Open this Blueprint, which is contained inside the Blueprints folder of Content Browser.

There is only one chain of Blueprint nodes inside this Blueprint, which are all triggered by Event Hit. We will have to add our new nodes close to the end of this chain, after all nodes except DestroyActor. There must not be other nodes after a DestroyActor node whose Target is self because this node removes the current instance from the Level. Break the link between the Spawn Emitter at Location and DestroyActor nodes, and then move DestroyActor to the right to give plenty of room for our new Blueprint scripting. The goal is to create a series of nodes that will extract the current Target Kill Count from the player character and increase it by one before going on to destroy the Actor. The end result will look like this:

Target Kill Count is a variable of the FirstPersonCharacter Blueprint, so just as we did when we created our bindings earlier in the chapter, we need to get the player character object and cast it to the Cast To FirstPersonCharacter node. Add a Get Player Character node, and then connect its Return Value pin to a Cast To FirstPersonCharacter node.

Now, drag a wire from the As First Person Character pin to empty grid space, and then add a GET Target Kill Count node. From that node's output pin, create an integer + integer node, changing the bottom field to 1. Next, drag this new node's output pin into empty space and create a SET Target Kill Count node. Additionally, you have to drag a wire from the casting node's As First Person Character output pin to the Target input pin of the SET Target Kill Count node. Finally, connect the execution pins of the Cast To FirstPersonCharacter, SET Target Kill Count, and DestroyActor nodes, ensuring that DestroyActor is the final node in the chain. Compile, save, and Play the game to see the targets eliminated counter on the screen increase every time you destroy a target Cylinder:

Now, the ammo and goal counters are being modified by Events that occur within our game and the updated values are displayed immediately in the HUD.

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

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