I programmed a gun that shoots one bullet at a time and destroys enemies as follows:
function OnCollisionEnter2D (myCol: Collision2D){
if(myCol.gameObject.tag == tagToDestroy){
Destroy(myCol.gameObject);
Destroy(this.gameObject);
Debug.Log("A bullet destroyed something");
}
}
It works perfectly fine when my gun shoots one bullet at a time. Then I programmed a shotgun which fires 3 bullets at the same time, on slightly different angles.
When 2 or 3 bullets hit the same enemy from the same trigger pull, the enemy is destroyed, but only one of the bullets is destroyed. The others which hit the same enemy bounce off the enemy. I’m a bit confused because it seems like 3 bullets are having collision detected (or else why would they bounce off?) but only one of them gets destroyed. I even turned off hit detection between bullets which did not fix it. I also tried changing the order that the bullet/enemy are destroyed which didnt fix it either.