Player Death Audio Not Playing in Coroutine.

I have a Player Death Script which would start a coroutine if the Player’s health is <= 0.

Most of the Coroutine plays out the way it should. The only problem is the AudioSource deathScream, it doesn’t immediately play when the coroutine starts and sometimes it doesn’t play at all. Is there something I’m missing with my code? I look forward to an answer.

When your health drops to zero or below, you will fire the Death coroutine every single frame, and if you play an audiosource every single frame it keeps trying to play the clip from the beginning, but never gets a chance to play through it

You need to only be calling that Death coroutine once, so use a flag to determine whether they’re already dying or not.

Should I use a Bool to check if the play has died? Then if it’s true then Start Coroutine?

if (currentHealth <= 0 && bIsAlive)
{
  bIsAlive = false;
  ....PlayerHasDied();
}

Hey brotha, just to let ya know I finally got it to work. Apparently the real problem was that my health variable is static and is being updated, so I just made it a normal float instead. Thx for the help tho.

1 Like