-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSoundManager.cs
56 lines (44 loc) · 1.34 KB
/
SoundManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
SoundManager is the initial class used to control sound.
*/
public class SoundManager : MonoBehaviour
{
// Audio players components.
public AudioSource _audios;
public AudioClip[] audioClipArray;
// Singleton instance.
public static SoundManager Instance = null;
// Initialize the singleton instance.
private void Awake()
{
_audios = GetComponent<AudioSource>();
// If there is not already an instance of SoundManager, set it to this.
if (Instance == null)
{
Instance = this;
}
//If an instance already exists, destroy whatever this object is to enforce the singleton.
else if (Instance != this)
{
Destroy(gameObject);
}
//Set SoundManager to DontDestroyOnLoad so that it won't be destroyed when reloading our scene.
DontDestroyOnLoad(gameObject);
}
// Play a single clip through the sound effects source.
public void PlayMenu()
{
Debug.Log("[SOUND MANAGER]:playStart()");
_audios.clip = audioClipArray[0];
// _audios.PlayOneShot(_audios.clip);
_audios.Play();
}
public void StopMenuMusic()
{
Debug.Log("[SOUND MANAGER]:STOP()");
_audios.Stop();
}
}