예제 #1
0
    //private void OnTriggerStay2D(Collider2D collision)
    //{
    //    HandleEnemyCollision(collision);
    //}

    private void HandleEnemyCollision(Collider2D collision)
    {
        if (collision.gameObject.tag == "Enemy" && isMelee)
        {
            lastHit = 0.0f;
            Debug.Log("hit enemy");
            Enemy enemy = collision.gameObject.GetComponentInParent <Enemy>();
            if (melee != null && melee.IsMelee())
            {
                Rigidbody2D colrb = collision.gameObject.GetComponentInParent <Rigidbody2D>();
                colrb.velocity = new Vector2(0.0f, colrb.velocity.y);
                colrb.AddForce(GameObject.FindWithTag("Player").transform.localScale.x *Vector2.right * 20.0f, ForceMode2D.Impulse);
                enemy.health -= melee.GetDamage();
            }
        }
    }