From 8dbd9243e1ae0a5621ea8cb93e11a1f9387be301 Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sun, 21 Apr 2024 10:53:16 +0200 Subject: [PATCH] fixes --- Assets/Scripts/Manager/AudioManager.cs | 22 ++++++++-------------- Assets/Scripts/Manager/GameManager.cs | 9 +++++++-- Assets/Scripts/Manager/MusicManager.cs | 6 ++++++ 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/Manager/AudioManager.cs b/Assets/Scripts/Manager/AudioManager.cs index 74af36f..802f4ac 100644 --- a/Assets/Scripts/Manager/AudioManager.cs +++ b/Assets/Scripts/Manager/AudioManager.cs @@ -2,7 +2,6 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using Unity.VisualScripting; using UnityEngine; public class AudioManager : MonoBehaviour @@ -11,28 +10,23 @@ public class AudioManager : MonoBehaviour public AudioLibraryObject audioLibrary; - private void OnEnable() + private void Awake() { - if (Instance is null) + if (Instance != null) { - Instance = this; + Destroy(this); // TODO: manager itself should not handle this // DontDestroyOnLoad(this); + return; } - else - { - Destroy(Instance); - Instance = this; - } - } - - private void OnDisable() - { - Instance = null; + Instance = this; } public static AudioClip FindAudioClip(string nameOfClip) { + Debug.Log(nameOfClip); + Debug.Log(Instance); + Debug.Log(Instance.audioLibrary); return Instance.audioLibrary.Clips.First(x => x.name == nameOfClip); } diff --git a/Assets/Scripts/Manager/GameManager.cs b/Assets/Scripts/Manager/GameManager.cs index 8889b02..79816b6 100644 --- a/Assets/Scripts/Manager/GameManager.cs +++ b/Assets/Scripts/Manager/GameManager.cs @@ -30,8 +30,13 @@ public class GameManager : MonoBehaviour private void Awake() { - if (Instance != this) - Destroy(Instance); + if (Instance != null) + { + Destroy(gameObject); + return; + + } + Instance = this; health = startHealth; } diff --git a/Assets/Scripts/Manager/MusicManager.cs b/Assets/Scripts/Manager/MusicManager.cs index 086035f..5f43264 100644 --- a/Assets/Scripts/Manager/MusicManager.cs +++ b/Assets/Scripts/Manager/MusicManager.cs @@ -16,6 +16,12 @@ public class MusicManager : MonoBehaviour void Awake() { + if (Instance != null) + { + Destroy(this); + return; + } + Instance = this; sources = new AudioSource[intensities.Length]; }