Example #1
0
    public void ApplyDamage(float damage)
    {
        if (shieldActivated)
        {
            comboSoundCounter = 0;
            health           -= 1;
            soundFX.Block();
        }
        else
        {
            comboSoundCounter++;
            health -= damage;
            soundFX.Hurt();
            if (comboSoundCounter >= 3)
            {
                StartCoroutine(ComboNoiseFunction());
            }
        }


        if (health_UI != null)
        {
            health_UI.fillAmount = health / 100f;
        }

        if (health <= 0)
        {
            Scene  currentScene = SceneManager.GetActiveScene();
            string sceneName    = currentScene.name;
            soundFX.Die();

            GetComponent <Animator>().enabled = false;

            //print("the character died");
            StartCoroutine(AllowRotate());

            if (isPlayer)
            {
                GetComponent <PlayerMove>().enabled        = false;
                GetComponent <PlayerAttackInput>().enabled = false;

                //the player is not the parent game object
                //for the camera anymore
                Camera.main.transform.SetParent(null);

                if (sceneName == "gameplay")
                {
                    GameObject.FindGameObjectWithTag(Tags.ENEMY_TAG)
                    .GetComponent <EnemyController>().enabled = false;
                }
            }
            else
            {
                GetComponent <EnemyController>().enabled = false;
                GetComponent <NavMeshAgent>().enabled    = false;
            }
        }
    }//apply damage