AudioClip chopped and delaying audio play

Hi guys, I need some help with a sound problem I found while programming a game.

I have an event (pointer click) and I need to play a sound inside that event.

To play the sound I’m using:

AudioSource.PlayClipAtPoint(pop, transform.position, 1f);

After the instruction I have a bunch of lines with code and then I reload the scene to restart all over again.

So far, the sound is played but is chopped by the scene reload (I guess…), so I try using a delay

IEnumerator WaitingForSomething()
    {
        UnityEngine.Debug.Log("Before Waiting");
        yield return new WaitForSeconds(2);
        UnityEngine.Debug.Log("After Waiting");
        print(Time.time);
    }

but it didn’t work. Google lead me to this answer about the execution of WaitForSeconds(). My WaitingForSomething() never print the after waiting debug or the Time.time because when it reach the yield return, it returns to where it was before and the next 50 lines of code are executed so fast that the 2 seconds are chopped by the scene reload.

So my questions are:

  1. How can I enforce the full playback of the AudioClip?

  2. If I can’t enforce the full playback of the AudioClip, is there a way to force Unity3D to stop and wait until the AudioClip is fully played?

Thanks.

Try putting the code that reloads the scene in the WaitingForSomething() as well.

Basically, sound starts playing, wait for seconds until sound finishes playing, reload scene.

All of that in WaitingForSomething() so that it’ll actually wait before the scene reloads itself.