private void OnDestroy() { if (this == instance) { instance = null; } }
// Start is called before the first frame update private void Awake() { DontDestroyOnLoad(gameObject); audioSource = GetComponent <AudioSource>(); defaultVolume = audioSource.volume; decayRate = 0f; if (instance != null && instance != this) { if (audioSource.clip != instance.audioSource.clip || !instance.audioSource.isPlaying) { instance.defaultVolume = defaultVolume; ChangeAudio(audioSource.clip, audioSource.loop); } Destroy(gameObject); } else { instance = this; } }