Add Arrow Damage

Hey there.

I can’t seem to add +arrow damage to the overall damage. Rick said you could just modify the script to add the extra damage of the arrow to the damage of the bow if you wanted, but I can’t seem to figure out how to do it.


Can anyone tell me what I might be doing wrong or what step I might have missed.

Thank you so much. :slight_smile:

Let’s see if the correct amount of damage is being sent to the arrow in the first place by adding some Debugs.

public void SetTarget(Health target, float arrowDamage)
{
     Debug.Log($"Arrow fired for {arrowDamage} damage");
     this.target=target;
     this.arrowDamage = arrowDamage;
}
private void OnTriggerEnter(Collider other)
{
     if(other.GetComponent<Health>() !=target) return;
     Debug.Log($"Hitting {target} for {arrowDamage}");
     target.TakeDamage(arrowDamage);
     Destroy(gameObject);
}

Firstly… Thankyou so much for your help Brian.

So I added your code to the Projectile.sc and got this from the console


I should also state that the damage on the bow is set to 10 and the damage on the arrow is set to 2, so I should be seeing 12 as the total damage.
image
image
So the damage from the bow is still coming through, but the arrow damage isn’t being added. This is what I was getting before, it just wasn’t adding the arrow damage for some reason.

Let me know if you need anymore screen shots from any of the code scripts, or the Inspector, ect… if that will help.

Again, Thankyou so much Brian.

Ok, I think I understand what you’re going for. In Setup, you’re overwritting arrowDamage.

In SetTarget, try this instead:

this.arrowDamage+=arrowDamage;  //this is confusing, I would change the SetTarget parameter to damage

+= adds the damage to the arrowDamage instead of replacing it.

Yup. That was what I was missing the “+” in front of the “=”


And you can see it is working. :grinning:

Thank you so much Brian for your help. :+1:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms