summaryrefslogtreecommitdiff
path: root/Assembly_CSharp/AudioPoolSource.cs
blob: 883151da49501ecae7ba04c6102dfe9de90e05bd (plain)
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
using UnityEngine;

public class AudioPoolSource : MonoBehaviour
{
	[SerializeField]
	private AudioSource audioS;

	private float timer = -1f;

	private bool active;

	public void PlayClip(AudioClip clip, float volume, float pitchVariance)
	{
		audioS.Stop();
		audioS.clip = clip;
		audioS.pitch = 1f + Random.Range(0f - pitchVariance, pitchVariance);
		audioS.volume = volume;
		timer = clip.length + 0.1f;
		active = true;
		audioS.Play();
	}

	private void Update()
	{
		if (!active)
		{
			return;
		}
		timer -= Time.deltaTime;
		if (timer <= 0f)
		{
			active = false;
			if (base.transform.parent != null)
			{
				base.transform.parent = null;
			}
			SFXManager.instance.sources.Add(this);
		}
	}
}