Exemplo n.º 1
0
    public bool takeDamage(int amount)
    {
        //Particals
        Instantiate(particalEffect, transform.position, Quaternion.identity);

        //Animation
        bool facingRight = GameObject.FindGameObjectWithTag("Player").GetComponent <Movement>().isFacingRight();

        if (facingRight)
        {
            enemyAnimator.SetTrigger("hit_fl");
        }
        else
        {
            enemyAnimator.SetTrigger("hit");
        }

        //screen shake
        camShake.shake();

        //Sound
        FindObjectOfType <AudioManager>().play("Chop");

        //Damage
        health -= amount;

        //Healthbar
        if (healthDisplay.enabled == false)
        {
            healthDisplay.enabled = true;
        }
        healthBar.fillAmount = (float)health / (float)MAX_HEALTH;

        if (health <= 0)
        {
            die();
            return(true);
        }
        return(false);
    }