Example #1
0
 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.gameObject.tag != "Projectile")
     {
         if (col.gameObject.tag == "Enemy" && allegiance == Allegiance.Good)
         {
             HPScript hpScript = col.gameObject.GetComponent <HPScript> ();
             if (hpScript != null)
             {
                 hpScript.Damage(damage);
             }
             else
             {
                 Debug.LogWarning("Enemy [" + col.gameObject.name + "] doesn't have an HPScript.");
             }
             Destroy(gameObject);
         }
         else if (col.gameObject.tag == "Player" && allegiance == Allegiance.Bad)
         {
             HPScript hpScript = col.gameObject.GetComponent <HPScript> ();
             if (hpScript != null)
             {
                 hpScript.Damage(damage);
             }
             else
             {
                 Debug.LogWarning("Player [" + col.gameObject.name + "] doesn't have an HPScript.");
             }
             Destroy(gameObject);
         }
     }
 }
Example #2
0
    void OnTriggerEnter2D(Collider2D col)
    {
        bool foundIt = false;

        for (int i = 0; !foundIt && i < tagList.Length; i++)
        {
            if (col.tag.Equals(tagList [i]))
            {
                Debug.Log("[" + col.name + "] was hit by [" + name + "]. " + damage + " DAMAGE.");
                HPScript s = col.gameObject.GetComponent <HPScript> ();
                if (s != null)
                {
                    s.Damage(damage);
                }
            }
        }
    }