-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSoundManager.cs
43 lines (31 loc) · 878 Bytes
/
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
using UnityEngine;
using System.Collections;
public class SoundManager : MonoBehaviour
{
public AudioSource efxSource;
public AudioSource musicSource;
public static SoundManager instance = null;
public float lowPitchRange = .95f;
public float highPitchRange = 1.05f;
void Awake ()
{
if (instance == null)
instance = this;
else if (instance != this)
Destroy (gameObject);
DontDestroyOnLoad (gameObject);
}
public void PlaySingle(AudioClip clip)
{
efxSource.clip = clip;
efxSource.Play ();
}
public void RandomizeSfx (params AudioClip[] clips)
{
int randomIndex = Random.Range(0, clips.Length);
float randomPitch = Random.Range(lowPitchRange, highPitchRange);
efxSource.pitch = randomPitch;
efxSource.clip = clips[randomIndex];
efxSource.Play();
}
}