]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Audio/AudioManager.cs
be320bb6e1b0bd09f4489ec37d65b92fc2caa472
[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
9     void Awake()
10     {
11        foreach(Sound s in sounds)
12         {
13             s.source = gameObject.AddComponent<AudioSource>();
14             s.source.clip = s.clip;
15
16             s.source.volume = s.volume;
17             s.source.pitch = s.pitch;
18         } 
19     }
20
21     public void Start()
22     {
23         Play("flowers");
24     }
25
26     public void Play(string name)
27     {
28         Sound s = Array.Find(sounds, sound => sound.name == name);
29         s.source.Play();
30     }
31
32     public void Stop(string name) 
33     {
34         Sound s = Array.Find(sounds, sound => sound.name == name);
35         s.source.Stop();
36     }
37 }