If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.
Noooooooo! Ben is on to me!
@ben and @Rick_Davidson I have a question and a bug report. First off the thing to point out, with the area effect special attack the player gets damaged as well, was that intentional? And now for the bug report. My player seems to only play the death animation yet the player will always play the sound, I’m using a different sound library which may be the problem. I think my code is the same as in the lecture, but just in case I will include the relevant parts of Player.cs
public void TakeDamage(float damage)
{
bool playerDies = (currentHealthPoints - damage <= 0f);
ReduceHealth(damage);
if (playerDies)
{
StartCoroutine(KillPlayer());
}
}
IEnumerator KillPlayer()
{
animator.SetTrigger(DEATH_TRIGGER);
audioSource.clip = deathSounds[Random.Range(0, deathSounds.Length)];
audioSource.Play();
yield return new WaitForSecondsRealtime(audioSource.clip.length);
SceneManager.LoadScene(0);
}
void ReduceHealth(float damage)
{
currentHealthPoints = Mathf.Clamp(currentHealthPoints - damage, 0f, maxHealthPoints);
audioSource.clip = hurtSounds[Random.Range(0, hurtSounds.Length)];
audioSource.Play();
}
Hi @midasPrimaris,
Your sentence “My player seems to only play the death animation yet the player will always play the sound” has me a little confused. Is the bug that one of death animation or sound is not playing? Or always playing? Or not randomising?
Actually, that’s fixed. I made one of those small annoying errors so common in programming and I didn’t tick Has Exit Time under the transition from attacking to death.
I’m glad it was a simple one to resolve!