using System; using UnityEngine; using UnityEngine.UI; public class SoundEffectManager : MonoBehaviour { private static AudioSource audioSource; private static SoundEffectLibrary soundEffectLibrary; [SerializeField] private Slider sfxSlider; private void Awake() { audioSource = GetComponent(); soundEffectLibrary = GetComponent(); } public static void Play(string soundName) { AudioClip audioClip = soundEffectLibrary.GetRandomClip(soundName); if (audioClip != null) { audioSource.PlayOneShot(audioClip); } } // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { sfxSlider.onValueChanged.AddListener(delegate {OnValueChanged();}); } public static void SetVolume(float volume) { audioSource.volume = volume; } public void OnValueChanged() { SetVolume(sfxSlider.value); } }