Why does my sound play after other code?

I have a litte IENumerator that ‘zaps’ my player. It is supposed to make a noise and set off a particle effect before moving the player to a different position. For some reason the sound doesn’t play until AFTER everything else even though it is the first command. I think I’m misunderstanding something very fundamental to Unity’s handling of sound…

IEnumerator ZapPlayer()
{
    audioPlayer.Play();
    playerScript.Zap(true);
    yield return new WaitForSeconds(0.5f);
    playerScript.Zap(false);
    RestartLevel();
}

Zap(true) starts my particle, Zap(false) stops it. The pause is to allow for the player to see the effect/hear the sound before they are teleported.

RestartLevel() just moves the player’s location.

Why does the sound not play until after the RestartLevel() line?

Well sound takes a physical amount of time to play out but the next frame will be just a tiny fraction of a second. Try adding a yeild return new WaitForSeconds immediately after the sound so it has time to play before the Zap kicks in.