예제 #1
0
 public void Attack()
 {
     if (touch)
     {
         if (target.gameObject.tag == "animal")
         {
             print("Hit animal");
             EnemyControler Ec = target.gameObject.GetComponent <EnemyControler>();
             if (Ec != null)
             {
                 Ec.animalChangeHealth(damage);
             }
             else
             {
                 Debug.LogError("Animal doesn't have script");
             }
         }
         else if (target.gameObject.tag == "slime")
         {
             slime sl = target.gameObject.GetComponent <slime>();
             sl.slimeChangeHealth(damage);
             Debug.Log("Hit Slime");
         }
         Debug.Log("Damage: " + damage);
     }
 }
예제 #2
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "animal")
     {
         print("Hit animal!!!");
         EnemyControler Ec = collision.gameObject.GetComponent <EnemyControler>();
         if (Ec != null)
         {
             Ec.animalChangeHealth(-1);
         }
     }
     else if (collision.gameObject.tag == "slime")
     {
         slime sl = collision.gameObject.GetComponent <slime>();
         sl.slimeChangeHealth(-1);
         Debug.Log("Hit Slime");
     }
     Destroy(this.gameObject);
 }