]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Audio/AudioManager.cs
Dialogue-System v0.5
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Audio / AudioManager.cs
1 using UnityEngine.Audio;
2 using System;
3 using UnityEngine;
4
5 public class AudioManager : MonoBehaviour
6 {
7     public Sound[] sounds;
8     public static AudioManager instance;
9
10     void Awake()
11     {
12         if (instance == null)
13         {
14             instance = this;
15         }
16         else
17         {
18             Destroy(gameObject);
19             return;
20         }
21
22         DontDestroyOnLoad(gameObject);
23
24         foreach (Sound s in sounds)
25         {
26             s.source = gameObject.AddComponent<AudioSource>();
27             s.source.clip = s.clip;
28
29             s.source.volume = s.volume;
30             s.source.pitch = s.pitch;
31         }
32     }
33
34     public void Play(string name)
35     {
36         Sound s = Array.Find(sounds, sound => sound.name == name);
37         s.source.Play();
38     }
39 }