void Awake() { if (Application.isPlaying) { instance = this; DontDestroyOnLoad (gameObject); } bgm = gameObject.GetComponent<AudioSource> (); if (bgm == null) { bgm = gameObject.AddComponent<AudioSource> (); } bgm.loop = true; if (sound == null) { GameObject gObj = new GameObject (); gObj.name = "Sound"; gObj.transform.parent = transform; gObj.AddComponent<Sound> (); sound = gObj.GetComponent<AudioSource> (); sound.playOnAwake = false; } }
/// <summary> /// Destory this instance. /// </summary> public void Destory() { instance = null; GameObject.Destroy (gameObject); }