void Start() { //newLoadedLevel = true; //persistentSource = new AudioSource(); //persistentSource = this.gameObject.GetComponents<AudioSource>()[1]; //Debug.Log("persistance source assigned: " + persistentSource); if (singleton != this) { if (singleton == null) { singleton = this; DontDestroyOnLoad(this.gameObject); loopSource = new AudioSource(); persistentSource = new AudioSource(); loopSource = this.gameObject.GetComponents<AudioSource>()[0]; //singleton.persistentSource = this.gameObject.GetComponents<AudioSource>()[1]; persistentSource = this.gameObject.GetComponents<AudioSource>()[1]; DontDestroyOnLoad(persistentSource); switch (Application.loadedLevel) { case 0: if (singleton.loopSource.clip != menuMusic) { singleton.playSustainedSound(menuMusic); } break; case 1: if (singleton.loopSource.clip != menuMusic) { singleton.playSustainedSound(menuMusic); } break; case 2: if (singleton.loopSource.clip != levelMusic) { singleton.playSustainedSound(levelMusic); } break; case 3: if (singleton.loopSource.clip != levelMusic) { singleton.playSustainedSound(levelMusic); } break; } //Debug.Log(loopSource); //Debug.Log(loopSource.clip); } else { switch (Application.loadedLevel) { case 0: if (singleton.loopSource.clip != menuMusic) { singleton.playSustainedSound(menuMusic); } break; case 1: if (singleton.loopSource.clip != menuMusic) { singleton.playSustainedSound(menuMusic); } break; case 2: if (singleton.loopSource.clip != levelMusic) { singleton.playSustainedSound(levelMusic); } break; case 3: if (singleton.loopSource.clip != levelMusic) { singleton.playSustainedSound(levelMusic); } break; } Destroy(this.gameObject); } } }