Reducing the ammo counter

We need to modify the player fire logic so that the ammo counter is decreased when the player fires their gun. The Blueprint nodes managing the firing of the player's gun are contained within the FirstPersonCharacter Blueprint. Find this Blueprint within the Blueprints folder of Content Browser and open it. Now, find the large series of Blueprint nodes contained within the Spawn projectile comment block. We want to ensure that the counter tracking the player's current ammo count reduces by one each time the player fires a shot. The Blueprint scripting required to do so looks like this:

Find the final node in the chain, Play Sound at Location. Drag a wire from the output execution pin of this node to empty grid space and add a SET Player Current Ammo node. Then, drag a wire from the Player Current Ammo input pin to empty space and create an integer – integer node. Next, drag a wire from the top input pin of this node out and add a GET Player Current Ammo node. Finally, in the bottom field of the integer – integer node, add  1. This sequence translates to the following: after firing a sound, set the player's current ammo count to the existing ammo count minus one. Compile, save, and press Play to see your ammo counter decrease every time you fire a shot from your gun.

The SET Player Current Ammo node and the subtract node of the previous screenshot can be replaced by the DecrementInt node, which subtracts 1 from the input variable and sets the new value in the input variable. There is also the IncrementInt node, which adds 1 to the input variable.
..................Content has been hidden....................

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