public void preserveBgm() { if (instance == null) { instance = this; } // 인스턴스가 존재하는 경우 새로생기는 인스턴스를 삭제한다. else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(this); GameObject g = GameObject.Find("KeepBGM"); }
void Awake() { /* * GameObject[] obj = GameObject.FindGameObjectsWithTag("sound"); * for (int i = 1; i < obj.Length; i++) * { * Destroy(obj[i]); * } */ if (instance == null) { instance = this; } // 인스턴스가 존재하는 경우 새로생기는 인스턴스를 삭제한다. else if (instance != this) { Destroy(gameObject); } DontDestroyOnLoad(this); }