[ad_1]
I’m engaged on my first Tower Defense sport and I’ve an issue the place the a number of enemies get hit by a projectile as an alternative of 1.
Enemy with it is collider.
The downside is that once they get shut to one another which is okay, their colliders overlap and one arrow offers injury to a number of items.
Arrow and Enemy each have set off colliders 2D
Code for Arrow.cs element
non-public void OnTriggerEnter2D(Collider2D collision) {
Enemy enemy = collision.GetComponent<Enemy>();
if (enemy != null) {
IDamagable damagable = enemy.GetComponent<IDamagable>();
if (damagable != null) {
damagable.ReceiveDamage(DamageType.PHYSICAL, attackType, injury);
} else {
Debug.Log("Unit is lacking the IDamagable script");
}
Destroy(gameObject);
}
}
Seems like collision detection and OnTriggerEnter2D is known as in the identical time and this perform runs a number of instances occasion if gameObject is destroyed. I attempted just a few approaches however with no luck.
Thanks prematurely!
[ad_2]