i shoot an arrow at a villain, i am using OnTriggerEnter to trigger the damage.
The debug log is telling me that the trigger is registered two or three times before the arrows collider is deleted. so the damage is two or three times what is intended. If I don’t delete the collider it can do up to 5 times the intended damage, but sometimes does less.
here is the code on the villain
public class villainHealth : MonoBehaviour {
public int startingHitPoints;
private int currentHitPoints;
// Use this for initialization
void Start ()
{
currentHitPoints = startingHitPoints;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "arrow")
{
currentHitPoints = (currentHitPoints - 1);
Destroy (other.collider);
VillainDeath ();
Debug.Log (currentHitPoints);
}
}
void VillainDeath ()
{
if(currentHitPoints <= 0)
Destroy(gameObject);
}
}
any thoughts on how to limit the damage to only the intended amount?
Thanks.