MAJOR: Re-organize entire project
This commit is contained in:
50
Assets/Scripts/Audio/BGMManager.cs
Normal file
50
Assets/Scripts/Audio/BGMManager.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Scampz.GameJam.Assets.Scripts
|
||||
{
|
||||
public class BGMManager : MonoBehaviour
|
||||
{
|
||||
public static BGMManager Instance { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
private AudioSource audioSource;
|
||||
|
||||
[SerializeField]
|
||||
private AudioClip[] backgroundMusic;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public void PlaySong()
|
||||
{
|
||||
audioSource.Stop();
|
||||
|
||||
var sceneCount = SceneManager.sceneCount;
|
||||
var scenes = new List<Scene>();
|
||||
|
||||
for (var i = 0; i < sceneCount; ++i)
|
||||
scenes.Add(SceneManager.GetSceneAt(i));
|
||||
|
||||
AudioClip audioClipToPlay = null;
|
||||
|
||||
if (scenes.Any(x => x.name.Contains("Temple")))
|
||||
audioClipToPlay = backgroundMusic[0];
|
||||
if (scenes.Any(x => x.name.Contains("Sanctum")))
|
||||
audioClipToPlay = backgroundMusic[1];
|
||||
|
||||
if (audioClipToPlay != audioSource.clip)
|
||||
{
|
||||
audioSource.clip = audioClipToPlay;
|
||||
audioSource.Play();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user