From 9027425c700c5e29116abd040f6d29693c9652c5 Mon Sep 17 00:00:00 2001 From: DerTyp187 Date: Sun, 2 Jan 2022 14:05:57 +0100 Subject: [PATCH] Update AudioManager.cs --- Assets/Scripts/Audio/AudioManager.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/Audio/AudioManager.cs b/Assets/Scripts/Audio/AudioManager.cs index aacf515..c3e52f3 100644 --- a/Assets/Scripts/Audio/AudioManager.cs +++ b/Assets/Scripts/Audio/AudioManager.cs @@ -1,9 +1,11 @@ -using UnityEditor.Audio; +using UnityEngine.Audio; using System; using UnityEngine; public class AudioManager : MonoBehaviour { + // This list contains all sounds which should be accessable by the audiomanager. + // If you want to add a sound -> add a new item in the list VIA the inspector! public Sound[] sounds; public static AudioManager instance; @@ -17,14 +19,14 @@ public class AudioManager : MonoBehaviour Destroy(gameObject); return; } - DontDestroyOnLoad(gameObject); + foreach(Sound s in sounds) { - s.source = gameObject.AddComponent(); - s.source.clip = s.clip; + s.source = gameObject.AddComponent(); // The Audio source where the "Player can hear through" + s.source.clip = s.clip; s.source.volume = s.volume; s.source.pitch = s.pitch; s.source.loop = s.loop; @@ -37,9 +39,10 @@ public class AudioManager : MonoBehaviour } + // USE this to play a sound in other scripts: FindObjectOfType().Play(name); public void Play(string name) { - Sound s = Array.Find(sounds, sound => sound.name == name); + Sound s = Array.Find(sounds, sound => sound.name == name); // searching for sound in Array where sound.name == name if(s == null) { Debug.LogWarning("Sound: " + s.name + " not found!");