private void Awake() { audioSource = GetComponent <AudioSource>(); if (instance == null) { instance = this; } else if (instance != this) { Destroy(gameObject); if (sceneIndex != SceneManager.GetActiveScene().buildIndex) { instance.SwitchBGM(); } sceneIndex = SceneManager.GetActiveScene().buildIndex; } DontDestroyOnLoad(gameObject); }