How to damage a health system?
Using functions, we can pass in damage to a function. It’s very simple. Let’s start with the health and damage ints.
Let’s start of by simply declaring how much health we have.
Now let’s create the function that will cause damage to health. We will cause this CauseDamage. The function will need to pass in the parameter damage.
Then in the update method, we will press the space and will trigger that function. Remember to apply the parameter in this as well.
I set the health to 10 and the damage to 2. Now when playing back, the player will reduce in health based on the space bar pressed.