lost me mind i did
This commit is contained in:
@@ -7,13 +7,12 @@ namespace Scampz.GameJam.Assets.Scripts
|
||||
{
|
||||
public class BGMManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioSource audioSource;
|
||||
|
||||
[SerializeField]
|
||||
private AudioClip[] backgroundMusic;
|
||||
|
||||
private static BGMManager _instance;
|
||||
private static AudioSource _audioSource;
|
||||
|
||||
public static BGMManager Instance
|
||||
{
|
||||
@@ -23,7 +22,9 @@ namespace Scampz.GameJam.Assets.Scripts
|
||||
{
|
||||
_instance = new GameObject().AddComponent<BGMManager>();
|
||||
_instance.name = _instance.GetType().ToString();
|
||||
_audioSource = new GameObject().AddComponent<AudioSource>();
|
||||
DontDestroyOnLoad(_instance.gameObject);
|
||||
DontDestroyOnLoad(_audioSource.gameObject);
|
||||
}
|
||||
|
||||
return _instance;
|
||||
@@ -32,7 +33,7 @@ namespace Scampz.GameJam.Assets.Scripts
|
||||
|
||||
public void PlaySong()
|
||||
{
|
||||
audioSource.Stop();
|
||||
_audioSource.Stop();
|
||||
|
||||
var sceneCount = SceneManager.sceneCount;
|
||||
var scenes = new List<Scene>();
|
||||
@@ -47,10 +48,10 @@ namespace Scampz.GameJam.Assets.Scripts
|
||||
if (scenes.Any(x => x.name.Contains("Sanctum")))
|
||||
audioClipToPlay = backgroundMusic[1];
|
||||
|
||||
if (audioClipToPlay != audioSource.clip)
|
||||
if (audioClipToPlay != _audioSource.clip)
|
||||
{
|
||||
audioSource.clip = audioClipToPlay;
|
||||
audioSource.Play();
|
||||
_audioSource.clip = audioClipToPlay;
|
||||
_audioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user