Fix World Camera
This commit is contained in:
@@ -1,33 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Scampz.GameJam.Assets.Scripts.Audio
|
||||
{
|
||||
public class BGM : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private AudioClip[] backgroundMusic;
|
||||
public AudioClip backgroundMusic;
|
||||
|
||||
public AudioClip GetClipFromSceneType(Scene scene)
|
||||
private void OnTriggerEnter(Collider collider)
|
||||
{
|
||||
AudioClip audioClipToPlay = null;
|
||||
|
||||
if (scene.name.Contains("Temple"))
|
||||
audioClipToPlay = backgroundMusic[0];
|
||||
if (scene.name.Contains("Sanctum"))
|
||||
audioClipToPlay = backgroundMusic[1];
|
||||
if (scene.name.Contains("Snow"))
|
||||
audioClipToPlay = backgroundMusic[2];
|
||||
if (scene.name.Equals("SnowC"))
|
||||
audioClipToPlay = backgroundMusic[3];
|
||||
if (scene.name.Contains("Airship"))
|
||||
audioClipToPlay = backgroundMusic[4];
|
||||
if (scene.name.Equals("AirshipInside"))
|
||||
audioClipToPlay = backgroundMusic[5];
|
||||
if (scene.name.Contains("Void"))
|
||||
audioClipToPlay = backgroundMusic[6];
|
||||
|
||||
return audioClipToPlay;
|
||||
if (collider.CompareTag("Player"))
|
||||
{
|
||||
var bgmManager = FindObjectOfType<BGMManager>();
|
||||
bgmManager.PlayBGM(backgroundMusic);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
using Scampz.GameJam.Assets.Scripts.Audio;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Scampz.GameJam.Assets.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(AudioSource))]
|
||||
public class BGMManager : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField]
|
||||
private BGM _backgroundMusic;
|
||||
|
||||
private static AudioSource _audioSource;
|
||||
|
||||
private void Awake()
|
||||
@@ -21,47 +15,11 @@ namespace Scampz.GameJam.Assets.Scripts
|
||||
_audioSource.loop = true;
|
||||
DontDestroyOnLoad(_audioSource.gameObject);
|
||||
}
|
||||
|
||||
if (_backgroundMusic == null)
|
||||
{
|
||||
Instantiate(_backgroundMusic);
|
||||
DontDestroyOnLoad(_backgroundMusic.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SceneManager.activeSceneChanged += PlayNextSongIfAreaChange;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SceneManager.activeSceneChanged -= PlayNextSongIfAreaChange;
|
||||
}
|
||||
|
||||
private void PlayNextSongIfAreaChange(Scene oldScene, Scene newScene)
|
||||
{
|
||||
if (_audioSource.clip == null)
|
||||
{
|
||||
var newMusic = _backgroundMusic.GetClipFromSceneType(newScene);
|
||||
PlayBGM(newMusic);
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log($"Changed scenes to " + newScene.name);
|
||||
var newAudioClip = _backgroundMusic.GetClipFromSceneType(newScene);
|
||||
|
||||
if (_audioSource.clip.name != newAudioClip.name)
|
||||
{
|
||||
PlayBGM(newAudioClip);
|
||||
}
|
||||
Debug.Log($"Playing BGM: " + _backgroundMusic.name);
|
||||
|
||||
}
|
||||
|
||||
public void PlayBGM(AudioClip audioClip)
|
||||
{
|
||||
if (_audioSource == null && _audioSource.clip == audioClip)
|
||||
if (_audioSource == null || _audioSource.clip == audioClip)
|
||||
return;
|
||||
|
||||
_audioSource.Stop();
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace Scampz.GameJam.Assets.Scripts.Audio
|
||||
public void PlaySoundEffect(string soundEffect)
|
||||
{
|
||||
var audioClip = GetClipFromName(soundEffect);
|
||||
_audioSource.PlayOneShot(audioClip);
|
||||
_audioSource.clip = audioClip;
|
||||
_audioSource.Play();
|
||||
}
|
||||
|
||||
public void StopSoundEffect()
|
||||
|
||||
Reference in New Issue
Block a user