From c9ca60b19fbb55178ff3d3f509e2817291031d35 Mon Sep 17 00:00:00 2001 From: SpoodyTheOne Date: Sat, 3 Feb 2024 14:22:53 +0100 Subject: [PATCH] Added basic sound manager --- Assets/Scripts/SoundManager.cs | 24 ++++++++++++++++++++++++ Assets/Scripts/SoundManager.cs.meta | 11 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 Assets/Scripts/SoundManager.cs create mode 100644 Assets/Scripts/SoundManager.cs.meta diff --git a/Assets/Scripts/SoundManager.cs b/Assets/Scripts/SoundManager.cs new file mode 100644 index 0000000..dcd3459 --- /dev/null +++ b/Assets/Scripts/SoundManager.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class SoundManager : MonoBehaviour +{ + private static SoundManager INSTANCE; + + private AudioSource source; + + void awake() { + if (SoundManager.INSTANCE == null) { + SoundManager.INSTANCE = this; + DontDestroyOnLoad(gameObject); + return; + } + + Destroy(gameObject); + } + + static void PlaySound(AudioClip clip, float volume = 1) { + INSTANCE.source.PlayOneShot(clip, volume); + } +} diff --git a/Assets/Scripts/SoundManager.cs.meta b/Assets/Scripts/SoundManager.cs.meta new file mode 100644 index 0000000..14e1640 --- /dev/null +++ b/Assets/Scripts/SoundManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 95cd959a7274673b79164bc2664ed6e0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: