Exemple #1
0
    // second TakeDamage function
    public void TakeDamage(int damage, bool onRepeat, float howManyTimes, float seconds, GameObject soundObj, string possibleDeathCause)
    {
        enemyAi.setSpeed(0.90f * enemyAi.getSpeed()); //Slow down when hit (if on repeat will slow down recursively) everytime called

        currentHealth -= damage;                      //take damage

        animator.SetTrigger("Go_To_Hit");

        audioManager.Play("SkeletonBoneCrack");

        if (currentHealth <= 0)
        {
            string deathCause = possibleDeathCause;
            Debug.Log(deathCause);
            Die(soundObj, deathCause);
            return;
        }
        else if (onRepeat && howManyTimes > 0) // repeat take damage (hit by a torch)
        {
            howManyTimes--;
            StartCoroutine(repeatHit(damage, onRepeat, howManyTimes, seconds, soundObj, possibleDeathCause)); // couroutine for repeating damage
        }
    }