Unity mainmenu audio problem.

I’m trying to have mainmenu have music playing in background, but when I load the level, and return back to mainmenu, the music doesn’t start. Also it breaks the audiosource so I have to restart Unity everytime I load back to mainmenu from other scene.

Here is the script im using to play audio:

var MenuAudio : AudioSource;


function Start() {

	MenuAudio.Play();
	print("Playing");
	
}

The video explains better than words.

Video Link

unitymainmenuaudioproblem

What you could do is in your load level script use the BroadcastMessage() function to tell the script to play the music. In the script you have shown add the following:

PlayMusic(play : boolean){
if(play){
MenuAudio.Play();
print("Playing");
}
}

And in the load level script, right after the Application.LoadLevel() line add the following:

BroadcastMessage("PlayMusic", true);