Example #1
0
        public void TakeDamage(float damage)
        {
            bool characterDies = (currenthealthPoints - damage) <= 0;

            currenthealthPoints = Mathf.Clamp(currenthealthPoints - damage, 0f, maxHealthPoints);
            var clip = hitSounds[(int)UnityEngine.Random.Range(0, hitSounds.Length)];

            audioSource.clip = clip;
            audioSource.Play();
            if (characterDies)
            {
                character.SetIsAlive(false);
                StartCoroutine(KillCharacter());
            }
        }