What is the correct way to pause background music?

Hi guys.

I'm struggling to get my music background to work. I have an emty gameobject with AudioSource attached, a 2D sound was dragged to the Audio Clip slot, a script like this was also attached to the gameobject:

function Awake () {
DontDestroyOnLoad (transform.gameObject);
function Start ()
audio.loop = true;

1st tried method. It works fine through all the scenes. There wasn't any "double sound" issue because i make the gameobject static. The only problem is that when i turn on/off the sound (audio.Pause()), the sound continues to play because Start function only gets called once in the lifetime of the behavior. Because of that, i used Update but the sound plays very laggy. What function should i use?

2nd tried method. I know that we can also pause the AudioListener, but when i minimize my game down the taskbar and later restore its window back, the sound plays for 1 or 2 seconds right before the scene is loaded even when the audio listener is in Pause mode. This can be very annoying :( How do i fix this?

The script attached to main camera:

function Update () {
if (!gamemusicmanager.musicon)
AudioListener.pause = true;
AudioListener.pause = false;

Can i have some suggestions from you guys?


try asking only one question at a time in future. For the 1st one of your question relating to the 1st script. Keep that as it is (if you say it's working) and also add an update function in which you can pause AND play the music.

As for the second question I believe someone has had the same problem, check this out, shows that Unity Answers is doing the job it was made for, I guess.

I’m using Unity 5.3.4f1 and the following (UnPause) makes the music resume at the point where it was paused. I use mp3s for my songs and the following is in Javascript.

    if (paused == true) {


    else if (paused == false) {