예제 #1
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag != "Player")
     {
         Health_Lv1 enemyHealth = collision.gameObject.GetComponent <Health_Lv1>();
         if (enemyHealth != null)
         {
             enemyHealth.TakeDamage(damage);
         }
         Destroy(gameObject);
         return;
     }
 }
예제 #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.name == "Walls")
        {
            Flip();
        }

        if (collision.tag == "Player")
        {
            Health_Lv1 playerHealth = collision.gameObject.GetComponent <Health_Lv1>();
            if (playerHealth != null)
            {
                playerHealth.TakeDamage(damage);
                collision.GetComponent <Player_Lv1>().KnockBack(transform);
                collision.GetComponent <Rigidbody2D>().AddForce(Vector2.left);
            }
        }
    }