31 lines
677 B
C#
31 lines
677 B
C#
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>();
|
|
_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();
|
|
}
|
|
}
|
|
}
|