How do I play a sound during a level change?

Earlier, I asked the question how to end a level. It was solved with the following script:

`//Script to revert winning player back to main menu`

`var levelToLoad : String;`

`function OnTriggerEnter(hit : Collider)` `{`

`Application.LoadLevel(levelToLoad);`

`}//END FUNCTION ONTRIGGERENTER`

Now, I want to add a sound to it. What I've attempted doing is creating a variable called triumph, and then using the audio.PlayOneShot code. However, this never plays it, and actually prevents the player from moving to the next level. I'm not sure how to add the sound to it. The sound is named Pop! Triumph! and it doesn't loop. Also, I'm not going to use any other sound, so it doesn't have to be a variable.

So can anyone make an addition to this script to make the sound play?

  1. Import your audio files into your Unity Project. These are now Audio Clips.
  2. Go to GameObject->Create Empty from the menubar.
  3. With the new GameObject selected, select Component->Audio->Audio Source.
  4. Assign the Audio Clip property of the Audio Source Component in the Inspector.

Hints:

* The key to a nice sound environment is tweaking the Rolloff Factor.
* 3D audio effects will only work for mono Audio Clips. Stereo Audio Clips will be mixed as-is into the sound output. 

I'll give u a C# verison, the sound file has to be in ur "Resources" Folder.

using UnityEngine;
using System.Collections;

public class Sound_Player: MonoBehaviour 
{
    AudioSource audio_source;
    AudioClip sound;
        // Use this for initialization
    void Start ()
    {
        audio_source = (AudioSource)gameObject.AddComponent("AudioSource");
        sound = (AudioClip)Resources.Load("File Name");
        audio_source.clip = sound;
    }
        // Update is called once per frame
    void Update ()
    {

    }

//Script to revert winning player back to main menu

var levelToLoad : String;

function OnTriggerEnter(hit : Collider) {

audio_source.Play();
Application.LoadLevel(levelToLoad);

}//END FUNCTION ONTRIGGERENTER

}

The problem is that the sound will be stopped when you try to load the next level

What I would do is play a sound (using audio.Play, not PlayOneShot), and wait until audio.IsPlaying is false. After that, load the level like you normally would

The reason why sound stops is that SoundClip and SoundSource are all destroyed while changing level.
Use “DontDestroyOnLoad” method and protect GameObjects with sound components.