Triggering a win

The final step for us is to determine the conditions that will result in the End Game custom Event being triggered. We want the Event to happen once the player has killed a sufficient number of target Cylinders to meet the target goal. We can evaluate this each time a target is destroyed. To do so, open CylinderTarget_Blueprint in the Blueprints folder and navigate to the end of the Blueprint chain in Event Graph.

We want to create a Branch node that will allow us to check if the last destroyed target was the last one needed to reach the goal. Attach a Branch node to the SET Target Kill Count node near the end of the chain. You can reattach the DestroyActor node to the False output of the Branch node.

Now we need to establish the condition that the branch will check. We are going to want to compare the Target Kill Count variable to see if it has reached or exceeded the Target Goal variable. To do so, create an integer >= integer node and drag its output pin to the Condition pin of the Branch node.

Next, find the GET Target Kill Count node that already exists and drag a second wire from its output pin to the top input pin of the integer >= integer node. Then, find the Cast To FirstPersonCharacter node and drag out a wire from its As First Person Character output pin onto a new GET Target Goal node. Drag the output pin of this new node to the bottom input pin of the integer >= integer node.

Now, drag the third wire from the Cast To FirstPersonCharacter node's output pin and attach it to a new End Game node, which will call our custom Event. Connect this node to the True output of the Branch node, and then make a second connection to the DestroyActor node after it. This should complete your branching logic and produce a result that looks like this:

Compile, save, and press Play to test the game. If all the Blueprints are set up correctly, then you should see the game pause and a victory menu appear as soon as you destroy a second target. Clicking on the Restart button will reload the Level from the start, and clicking Quit will close the play session.

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

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