コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: DealDamageToTag.cs プロジェクト: HUTeachers/HU18
 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);
         }
     }
 }