]> git.lizzy.rs Git - SuperMouseAdventure.git/blobdiff - 2DGame/Assets/Scripts/Audio/AudioManager.cs
Dialog-System 0.4
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Audio / AudioManager.cs
index 60934768ffcf14614c4b4b8ad8c0df932446a597..42526b301d3db8d7fad8bc674da3edcbcb367305 100644 (file)
@@ -5,28 +5,37 @@ using UnityEngine;
 public class AudioManager : MonoBehaviour
 {
     public Sound[] sounds;
+    public AudioSource currentSource;
+    public static AudioManager instance;
 
     void Awake()
     {
-       foreach(Sound s in sounds)
+        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;
-        } 
+        }
     }
 
     public void Play(string name)
     {
         Sound s = Array.Find(sounds, sound => sound.name == name);
-        s.source.Play();
-    }
-
-    public void Stop(string name) 
-    {
-        Sound s = Array.Find(sounds, sound => sound.name == name);
-        s.source.Stop();
+        currentSource = s.source;
+        currentSource.Play();
     }
-}
+}
\ No newline at end of file