You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
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<AudioSource>();
|
|
soundEffectLibrary = GetComponent<SoundEffectLibrary>();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|