void Awake() { if (instance != null && instance != this) { if (instance.GetComponent <AudioSource>().clip != gameObject.GetComponent <AudioSource>().clip) { instance.GetComponent <AudioSource>().clip = gameObject.GetComponent <AudioSource>().clip; instance.GetComponent <AudioSource>().volume = gameObject.GetComponent <AudioSource>().volume; instance.GetComponent <AudioSource>().Play(); } Destroy(this.gameObject); return; } instance = this; gameObject.GetComponent <AudioSource>().Play(); DontDestroyOnLoad(this.gameObject); }
public void BgmStop() { if (Instance == null) { bgm = gameObject.GetComponent <AudioSource>(); } else { bgm = Instance.GetComponent <AudioSource>(); } if (bgmcheck) { bgm.enabled = false; bgmcheck = false; } else { bgm.enabled = true; bgmcheck = true; } }
static public void Play() { instance.GetComponent <AudioSource>().Play(); }