summaryrefslogtreecommitdiff
path: root/GameCode/AudioPoolSource.cs
diff options
context:
space:
mode:
Diffstat (limited to 'GameCode/AudioPoolSource.cs')
-rw-r--r--GameCode/AudioPoolSource.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/GameCode/AudioPoolSource.cs b/GameCode/AudioPoolSource.cs
new file mode 100644
index 0000000..883151d
--- /dev/null
+++ b/GameCode/AudioPoolSource.cs
@@ -0,0 +1,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);
+ }
+ }
+}