]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Audio/AudioManager.cs
42526b301d3db8d7fad8bc674da3edcbcb367305
[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 AudioSource currentSource;
9     public static AudioManager instance;
10
11     void Awake()
12     {
13         if (instance == null)
14         {
15             instance = this;
16         }
17         else
18         {
19             Destroy(gameObject);
20             return;
21         }
22
23         DontDestroyOnLoad(gameObject);
24
25         foreach (Sound s in sounds)
26         {
27             s.source = gameObject.AddComponent<AudioSource>();
28             s.source.clip = s.clip;
29
30             s.source.volume = s.volume;
31             s.source.pitch = s.pitch;
32         }
33     }
34
35     public void Play(string name)
36     {
37         Sound s = Array.Find(sounds, sound => sound.name == name);
38         currentSource = s.source;
39         currentSource.Play();
40     }
41 }