I will paste code below. When I start game I want to load audio settings and change audio mixer volume parameters, in editor it doesn’t work, only SFX volume is changed, in build Master and all SFX volumes are changed during load but music volume parameter is not. I have no idea how to fix that, seems it is problem only when I load volume paramters from PlayerPrefs at the begining of the game, because when I tried to laod them when I enter audio settings menu everything works well. Maybe audiomixer is not ready yet on the begining of the game, do you see any ideas to solve that?
public override void OnStart()
{
base.OnStart();
LoadAudioSettings();
}
public void SetMasterVolume(float volume)
{
audioMixer.SetFloat("MasterVolume", volume);
}
public void SetMusicVolume(float volume)
{
audioMixer.SetFloat("MusicVolume", volume);
}
public void SetSFXVolume(float volume)
{
audioMixer.SetFloat("SFXVolume", volume);
audioMixer.SetFloat("SFX2Volume", volume);
}
public override void OnReturnInput()
{
if (menuInput.actions["Return"].triggered)
{
SaveAudioSettings();
OnBackPressed();
}
}
private void SaveAudioSettings()
{
float volume = masterVolumeSlider.value;
PlayerPrefs.SetFloat("MasterVolume", volume);
volume = musicVolumeSlider.value;
PlayerPrefs.SetFloat("MusicVolume", volume);
volume = sfxVolumeSlider.value;
PlayerPrefs.SetFloat("SFXVolume", volume);
}
private void LoadAudioSettings()
{
float volume = PlayerPrefs.GetFloat("MasterVolume");
masterVolumeSlider.value = volume;
volume = PlayerPrefs.GetFloat("MusicVolume");
musicVolumeSlider.value = volume;
volume = PlayerPrefs.GetFloat("SFXVolume");
sfxVolumeSlider.value = volume;
}
}