I am trying to set music to play throughout the game and continue between scenes with an empty gameobject that has the script below attached on my main scene. It starts fine and when I move to other scenes it continues to play, but when I switch scenes back from another scene back to the main scene it plays a second instance. I am checking for isPlaying, but it always returns false. Is this because the gameobject is a new instance so I am not checking the original instance that is first created when the game starts?
function Awake () {
//Also checked for gameMusic as a boolean, but that didn't work either
//var gameMusic : GameObject = GameObject.Find("gameMusic");
//if(gameMusic){ audio.Play(); }
Debug.Log("is audio playing - " + audio.isPlaying);
if (!audio.isPlaying) {
Debug.Log("audio was not playing so it was started");
audio.Play();
}
DontDestroyOnLoad (transform.gameObject);
}