Making a more modular IDamageable/attack scripts.
Objective: Create separate damage amounts for your attacks!
The flame sword does the exact same amount of damage as the regular sword. That doesn’t seem like much of a power up to me. We need to make the flame sword hit harder and it’s simple to do.
Let’s head to the IDamageable script and insert an int parameter on the damage method.
When adding a parameter to an interface method you need to add it to the base method. You will need to add this parameter to all who inherit from this interface. for this tutorial we are going to focus on one and you can copy the process over to the rest.
Add the parameter to the Damage method. The health will now be subtracted by this parameter since the amount will change depending on what the enemy is hit with.
Do you remember what calls the damage method? It’s the attack script. Head there and we will make two changes. First, we need an int variable to represent the attack points assigned. Use this variable as the parameter when calling the damage method.
In the unity editor the two hitboxes are what have the attack script attached. Select the original hitbox and set the attack point to 1. For me, I set the attack points of the flame sword to 3.
Now if you add more attacks in the future you can adjust its damage properties easier. Don’t be afraid to experiment with your attacks and damages and I’ll see you in the next tutorial!