protected override void OnTriggerSpecific(Collider other) { base.OnTriggerSpecific(other); if (other.CompareTag(gameObject.tag)) { return; } GameObjectDestroyByContact otherGameObjectDestroyByContact = other.GetComponent <GameObjectDestroyByContact>(); IDamageAble gameObjectDamageAble = gameObject.GetComponent <IDamageAble>(); if (gameObjectDamageAble != null) { if (otherGameObjectDestroyByContact != null) { gameObjectDamageAble.TakeDamage(otherGameObjectDestroyByContact.DamageValue); } else { gameObjectDamageAble.TakeDamage(1); } } else { Destroy(gameObject); } IDamageAble otherGameObjectDamageAble = other.GetComponent <IDamageAble>(); if (otherGameObjectDamageAble != null) { otherGameObjectDamageAble.TakeDamage(DamageValue); } else { Destroy(other.gameObject); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag(damageTag)) { collision.gameObject.GetComponent <IDamageAble>().TakeDamage(amount); } else { IDamageAble temp = collision.gameObject.GetComponent <IDamageAble>(); if (temp != null) { temp.TakeDamage(0); } } }