diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-20 23:26:03 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-20 23:26:03 -0400 |
| commit | ee3e85bc67a0f6f1761c11ea452d7bb862105930 (patch) | |
| tree | 8d065b97d833aba9761aacaeac7bc887f0b76af3 /Assets/Scripts/AudioManager.cs | |
| parent | 7c1e566113d59699af1624186c64eca67f063fc6 (diff) | |
| download | Project-Sandbox-ee3e85bc67a0f6f1761c11ea452d7bb862105930.tar.gz Project-Sandbox-ee3e85bc67a0f6f1761c11ea452d7bb862105930.tar.bz2 Project-Sandbox-ee3e85bc67a0f6f1761c11ea452d7bb862105930.zip | |
Audio works :D
Diffstat (limited to 'Assets/Scripts/AudioManager.cs')
| -rw-r--r-- | Assets/Scripts/AudioManager.cs | 50 |
1 files changed, 50 insertions, 0 deletions
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 <AudioSource>();
+ 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();
+ }
+}
|
