Add options menu and sound volume options logic
This commit is contained in:
parent
dfed2cc0e4
commit
91482820da
5 changed files with 1384 additions and 12 deletions
|
@ -5,13 +5,19 @@ using UnityEngine;
|
|||
public class SoundManager : MonoBehaviour
|
||||
{
|
||||
|
||||
private const string PLAYER_PREFS_SFX_VOLUME = "SFXVolume";
|
||||
|
||||
public static SoundManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private AudioClipsRefsSO audioClipsRefsSO;
|
||||
|
||||
private float volume;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
volume = PlayerPrefs.GetFloat(PLAYER_PREFS_SFX_VOLUME, 1f);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
|
@ -64,9 +70,9 @@ public class SoundManager : MonoBehaviour
|
|||
PlaySound(audioClipArray[Random.Range(0, audioClipArray.Length)], position, volume);
|
||||
}
|
||||
|
||||
private void PlaySound(AudioClip audioClip, Vector3 position, float volume = 1f)
|
||||
private void PlaySound(AudioClip audioClip, Vector3 position, float volumeMultiplier = 1f)
|
||||
{
|
||||
AudioSource.PlayClipAtPoint(audioClip, position, volume);
|
||||
AudioSource.PlayClipAtPoint(audioClip, position, volumeMultiplier * volume);
|
||||
}
|
||||
|
||||
public void PlayFootsteps(Vector3 position, float volume)
|
||||
|
@ -74,4 +80,21 @@ public class SoundManager : MonoBehaviour
|
|||
PlaySound(audioClipsRefsSO.footstep, position, volume);
|
||||
}
|
||||
|
||||
public void ChangeVolume()
|
||||
{
|
||||
volume += .1f;
|
||||
|
||||
if (volume >= 1.1f) {
|
||||
volume = 0f;
|
||||
}
|
||||
|
||||
PlayerPrefs.SetFloat(PLAYER_PREFS_SFX_VOLUME, volume);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public float GetVolume()
|
||||
{
|
||||
return volume;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue