This commit is contained in:
Sveske Juice 2024-04-21 10:53:16 +02:00
parent 13100a8399
commit 8dbd9243e1
3 changed files with 21 additions and 16 deletions

View File

@ -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;
}
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);
}

View File

@ -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;
}

View File

@ -16,6 +16,12 @@ public class MusicManager : MonoBehaviour
void Awake()
{
if (Instance != null)
{
Destroy(this);
return;
}
Instance = this;
sources = new AudioSource[intensities.Length];
}