From ee3e85bc67a0f6f1761c11ea452d7bb862105930 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Mon, 20 Apr 2020 23:26:03 -0400 Subject: Audio works :D --- Assets/Scripts/AudioManager.cs | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Assets/Scripts/AudioManager.cs (limited to 'Assets/Scripts/AudioManager.cs') diff --git a/Assets/Scripts/AudioManager.cs b/Assets/Scripts/AudioManager.cs new file mode 100644 index 0000000..23042c1 --- /dev/null +++ b/Assets/Scripts/AudioManager.cs @@ -0,0 +1,50 @@ +using UnityEngine; +using UnityEngine.Audio; +using System; + +public class AudioManager : MonoBehaviour +{ + public Sound[] sounds; + + public static AudioManager instance; + + // Start is called before the first frame update + void Awake() + { + if (instance == null) + instance = this; + else + { + Destroy(gameObject); + return; + } + + DontDestroyOnLoad(gameObject); + + foreach (Sound s in sounds) + { + s.source = gameObject.AddComponent (); + s.source.clip = s.clip; + + s.source.volume = s.volume; + s.source.pitch = s.pitch; + s.source.loop = s.loop; + } + } + + void Start() + { + Play("Splattack!"); + } + + public void Play(string name) + { + Sound s = Array.Find(sounds, sound => sound.name == name); + if (s == null) + { + Debug.LogWarning("Sound: " + name + " not found!"); + return; + } + s.source.Play(); + } +} -- cgit v1.2.3