summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/AudioManager.cs50
-rw-r--r--Assets/Scripts/AudioManager.cs.meta11
-rw-r--r--Assets/Scripts/Sound.cs21
-rw-r--r--Assets/Scripts/Sound.cs.meta11
4 files changed, 93 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();
+ }
+}
diff --git a/Assets/Scripts/AudioManager.cs.meta b/Assets/Scripts/AudioManager.cs.meta
new file mode 100644
index 0000000..243aa11
--- /dev/null
+++ b/Assets/Scripts/AudioManager.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5fe85533f1d727df19e1652886eea897
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Scripts/Sound.cs b/Assets/Scripts/Sound.cs
new file mode 100644
index 0000000..d7214a2
--- /dev/null
+++ b/Assets/Scripts/Sound.cs
@@ -0,0 +1,21 @@
+using UnityEngine;
+using UnityEngine.Audio;
+
+[System.Serializable]
+public class Sound
+{
+ public string name;
+
+ public AudioClip clip;
+
+ [Range(0f, 1f)]
+ public float volume;
+ [Range(.1f, 3)]
+ public float pitch;
+
+ public bool loop;
+
+ [HideInInspector]
+ public AudioSource source;
+
+}
diff --git a/Assets/Scripts/Sound.cs.meta b/Assets/Scripts/Sound.cs.meta
new file mode 100644
index 0000000..3a3da0e
--- /dev/null
+++ b/Assets/Scripts/Sound.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c1898fe7eafa1cd4e91085e11b27a27d
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: