Question by
Banditmayonnaise · Feb 08, 2021 at 10:11 PM ·
audio2d-platformerloadsave databinaryformatter
Binary formatter for saving sound settings (Slider doesn't remember fill area)
Hi Right now the game saves player settings for the master volume, and when I reopen the game, the sound settings are set as the previous value(the saved value). The problem is that the slider's fill area doesn't get saved, so it will always start with being full.
public float currentVolumeForMaster;
[Space]
[Header("New Saved Value")]
public float newVolumeForMaster;
void Start()
{
if ((System.IO.File.Exists(Application.persistentDataPath + "Player.Preferences")))
{
LoadSettingsData();
changeMasterVolume(newVolumeForMaster);
}
}
public void SetMasterVolume(float volume)
{
audioMixer.SetFloat("MasterVolume", Mathf.Log10(volume) * 20);
currentVolumeForMaster = volume; //CurrentVolumeForMaster is saved in the binary formatter
}
public void LoadSettingsData()
{
SavingSettingsData savingSettingsData = SaveSystem.LoadPlayerPreferences();
newVolumeForMaster = savingSettingsData.masterVolume;
}
public void changeMasterVolume(float newVolume)
{
//newVolume = newVolumeForMaster;
audioMixer.SetFloat("MasterVolume", Mathf.Log10(newVolume) * 20);
}
Thank you for reading this.
Comment