void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
// Use this for initialization void Start() { allAudioSources = FindObjectsOfType(typeof(AudioSource)) as AudioSource[]; foreach (AudioSource audioS in allAudioSources) { audioS.Stop (); } GetComponent<AudioSource>().Play(); if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }