-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyAudio.cs
86 lines (74 loc) · 2.05 KB
/
MyAudio.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MyAudio : MonoBehaviour {
private static MyAudio _current;
public static MyAudio current
{
get
{
if(_current != null)
return _current;
Debug.LogError("no audio");
return null;
}
set
{
_current = value;
}
}
void Awake()
{
if(_current == null)
{
_current = this;
}
else
{
Destroy(gameObject);
}
}
public enum AUDIOCLIPS { explosion, bang, lightsaber, lasergun, metalSlash, thud, revving, hiss, none}
public AUDIOCLIPS reference;
public List<AudioClip> explosions;
public List<AudioClip> bangs;
public List<AudioClip> lightsabers;
public List<AudioClip> laserguns;
public List<AudioClip> metalSlashs;
public List<AudioClip> thuds;
public List<AudioClip> revvings;
public List<AudioClip> hisss;
private List<List<AudioClip>> allClips = new List<List<AudioClip>>();
public AudioClip backgroundMusic;
public AudioSource backgroundSource;
public bool PlayBackground;
void Start()
{
allClips.Add(explosions);
allClips.Add(bangs);
allClips.Add(lightsabers);
allClips.Add(laserguns);
allClips.Add(metalSlashs);
allClips.Add(thuds);
allClips.Add(revvings);
allClips.Add(hisss);
backgroundSource.clip = backgroundMusic;
if(PlayBackground)
backgroundSource.Play();
}
public void PlayClip(AUDIOCLIPS clip)
{
if(clip == AUDIOCLIPS.none)
return;
List<AudioClip> group = allClips[(int)clip];
AudioClip c = group.GetRandom();
AudioSource.PlayClipAtPoint(c, Vector3.zero);
}
public AudioClip GetClip(AUDIOCLIPS clip)
{
if(clip == AUDIOCLIPS.none)
return null;
List<AudioClip> group = allClips[(int)clip];
return group.GetRandom();
}
}