Menu Music Issue!!

Hello, I’m using DontDestroyOnLoad to play music through various menu scenes, the code looks like :

function Awake() {
    // see if we've got game music still playing
    var gameMusic : GameObject = GameObject.Find("GameMusic");
    if (gameMusic) {
        // kill game music
        Destroy(gameMusic); 
    }
    // make sure we survive going to different scenes
    DontDestroyOnLoad(gameObject);
}


function Awake() {
    // see if we've got menu music still playing
    var menuMusic : GameObject = GameObject.Find("MenuMusic");
    if (menuMusic) {
        // kill menu music
        Destroy(menuMusic);
    }
    // make sure we survive going to different scenes
    DontDestroyOnLoad(gameObject);
}

since I have used play on awake, the music starts from beginning whenever I move back from submenu’s to the main menu…Then I will have two music playing at the same time…
Is there any way I could stop this from happening?

Hello,

Create an empty game object in first menu scene with tag name music and add audio source component to the GameObject playing your music automatically and then use the following code,may be help.

void Awake ()

{
	if (GameObject.FindGameObjectsWithTag ("music").Length > 1)
					Destroy (this.gameObject);
	DontDestroyOnLoad(gameObject);
	
}

Thanks

Ram