Ok, I’ve been searching around for awhile for a music playing script that continues across scenes but destroys when it returns to the first scene, I finally found one. But this script calls for MyUnitySingleton, which first of all I have no idea how to declare or make a singleton for it to reference to. Here is the link to the code.
http://answers.unity3d.com/questions/11314/audio-or-music-to-continue-playing-between-scene-c.html
I don’t know what the MyUnitySingleton is that they are referring to. I’m trying to use the second commented code:
The first function:
private static var instance:MyUnitySingleton;
public static function GetInstance() : MyUnitySingleton {
return instance;
}
function Awake() {
if (instance != null && instance != this) {
Destroy(this.gameObject);
return;
} else {
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
And the second:
var NewMusic: AudioClip; //Pick an audio track to play.
function Awake ()
{
var go = GameObject.Find("Game Music"); //Finds the game object called Game Music, if it goes by a different name, change this.
go.audio.clip = NewMusic; //Replaces the old audio with the new one set in the inspector.
go.audio.Play(); //Plays the audio.
}
Help on what a singleton is, how to make one/declare one, and how to get this script to work would be great.