Music on multiple scenes

function Awake()

{ var gameMusic : GameObject = GameObject.Find("GameMusic");

DontDestroyOnLoad(gameObject);

if (gameMusic)
    {
        Destroy(gameMusic);
    }

}

This script allows the background music to play through the different scenes, but when I get back to the main menu page, the music starts all over again, overlapping the one which is continuing from before. How do I stop this from happening?

Thank you.

try putting your music player on a level before your main menu page.

Another more robust way would be to make the sound player singleton. Seems like you are doing it backwards and destroys the old object and allows the new one to be created. Some pseudo code:

void Start()
{
   // Find GameObjects of same type
   // if num > 0
   // Destroy this.gameObject
   // Return

   // Do normal stuff
}