Scriptum/Assets/SaveMusicSettings.cs

53 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SaveMusicSettings : MonoBehaviour
{
[SerializeField] private Slider musicSlider = null;
private void Start()
{
LoadValues();
if (!PlayerPrefs.HasKey("musicVolume"))
{
PlayerPrefs.SetFloat("musicVolume",0.1f);
Load();
}
else
{
Load();
}
}
public void ChangeVolume()
{
AudioListener.volume = musicSlider.value;
}
private void Load()
{
musicSlider.value = PlayerPrefs.GetFloat("musicVolume");
}
private void Save()
{
PlayerPrefs.SetFloat("musicVolume", musicSlider.value);
}
public void SaveVolumeButton()
{
float musicValue = musicSlider.value;
PlayerPrefs.SetFloat("MusicValue", musicValue);
LoadValues();
}
void LoadValues()
{
float musicValue = PlayerPrefs.GetFloat("MusicValue");
musicSlider.value = musicValue;
}
}