using UnityEngine; namespace Scampz.GameJam.Assets.Scripts { [RequireComponent(typeof(AudioSource))] public class BGMManager : MonoBehaviour { private static AudioSource _audioSource; private void Awake() { if (_audioSource == null) { _audioSource = new GameObject().AddComponent(); _audioSource.loop = true; DontDestroyOnLoad(_audioSource.gameObject); } } public void PlayBGM(AudioClip audioClip) { if (_audioSource == null || _audioSource.clip == audioClip) return; _audioSource.Stop(); _audioSource.clip = audioClip; _audioSource.Play(); } } }