Audio Scene swapping problem

Hi everyone !
So i have 2 scripts which i want to bassicly do this : Have the same audio as in the main menu(my main menu has 4 scenes) and a different ambient sound in the actual game itself. My first scripted ,i attached to an empty game object called Music and added the tag : GameController. i attached this script to it

var Clip1 : AudioClip;
var Clip2 : AudioClip;
function Start () {
DontDestroyOnLoad(gameObject);
if(Application.loadedLevel == “0”){
audio.clip = Clip1;
} else if(Application.loadedLevel == “5”){
audio.clip = Clip2;
}
}

i attached my second script to the main camera this is the script :

var music : GameObject;
function Start(){
var G : GameObject = GameObject.FindGameObjectWithTag(“GameController”);
if(!G){ Instantiate(music, Vector3.zero, Quaternion.identity);
}
}

When i run the game unity doesn’t give me any error ,but it doesn’t work for some reason :frowning:

Could anyone please help me?

The object is not being destroyed in between loading scenes. So the object only runs the start function once. So when you change level, the object is already running. So the start function is not being called, and your script is not working as desired.

What you can use is OnLevelWasLoaded : http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnLevelWasLoaded.html

function OnLevelWasLoaded( level : int ) 
{
	if ( level == 0 ) 
	{
		audio.Stop();
		audio.clip = Clip1;
		audio.Play();
	}
	else if ( level == 5 ) 
	{
		audio.Stop();
		audio.clip = Clip2;
		audio.Play();
	}
}

or you can check my answer here on using a Music Manager Singleton : Continuous music across multiple scenes - Unity Answers