ManajemenInformatika_E31230007/Assets/Scripts/ClickSoundManager.cs

49 lines
1.0 KiB
C#

using UnityEngine;
public class ClickSoundManager : MonoBehaviour
{
public static ClickSoundManager instance;
public AudioSource audioSource;
public AudioClip clickSound;
private float sfxVolume = 1f;
void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
instance = this;
DontDestroyOnLoad(gameObject);
if (audioSource == null)
audioSource = GetComponent<AudioSource>();
LoadVolume();
}
public void SetSFXVolume(float value)
{
sfxVolume = value;
audioSource.volume = value;
PlayerPrefs.SetFloat("SFX_VOLUME", value);
}
void LoadVolume()
{
sfxVolume = PlayerPrefs.GetFloat("SFX_VOLUME", 1f);
audioSource.volume = sfxVolume;
}
public void PlayClickSound()
{
if (audioSource != null && clickSound != null)
{
audioSource.PlayOneShot(clickSound, sfxVolume);
}
}
}