I have a detection if a bullet hits an enemy that's part of a script that's on an enemy:
void OnTriggerEnter (Collider other)
{
if (other.tag == "Bullet") {
Destroy (other); // or Destroy (other, 0);
}
}
The problem is when a bullet hits an enemy, its health drops to zero (from 100) as if it was hit more than once (I also checked with Debug.log).
So is there a way to make the bullet to destroy faster so it won't trigger again?
Also, should this detection script be on the enemy or on the bullet?
Instead of
Destroy(other)
useDestroy(other.gameObject)
. other is just a collider reference not the actual gameObject itself.Also just for good practice instead of comparing tag with == use
other.CompareTag(String tagName)
. Its less memory consuming.