void Awake() { if (music == null) { DontDestroyOnLoad(gameObject); //makes gameObject persist between level loads music = this; //sets this instance as the only instance } else if (music != this) { Destroy(gameObject); //if its not the only instance, destroy it } activeTheme = themes[initialActiveTheme]; foreach (AudioSource A in gameObject.GetComponents <AudioSource>()) { AudioChannels.Add(A); } activeAudioChannel = AudioChannels[0]; crossfadeAudioChannel = AudioChannels[1]; if (playOnAwake) { play(initialActiveTrack); } }
void Awake() { if (music == null) { DontDestroyOnLoad(gameObject); //makes gameObject persist between level loads music = this; //sets this instance as the only instance } else if (music != this) { Destroy(gameObject); //if its not the only instance, destroy it } activeTheme = themes[initialActiveTheme]; foreach (AudioSource A in gameObject.GetComponents<AudioSource>()) { AudioChannels.Add(A); } activeAudioChannel = AudioChannels[0]; crossfadeAudioChannel = AudioChannels[1]; if (playOnAwake) { play(initialActiveTrack); } }