예제 #1
0
    public virtual void TakeDamage(int damage)
    {
        if (target == null)
        {
            Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 1.0f, 1 << LayerMask.NameToLayer("Player"));

            foreach (Collider2D collider in colliders)
            {
                target = collider.gameObject.GetComponent <PlayerController>();
            }
        }
        health -= damage;
        if (health <= 0)
        {
            dropController.DropTreasure();
            PlayDieSound();
            gameObject.GetComponent <SpriteRenderer>().enabled = false;
            healthBarController.HideHealthBar();
        }

        healthBarController.UpdateHealthBar(health);
    }