Change volume with slider UI

As I understood, we have the OptionsController script on the Options scene to handle the volume (and difficulty) setup.
For the volume, OptionsController gets it from PlayerPrefsController.GetMasterVolume() upon start and sets it in MusicPlayer from slider in Update.

However, I didn’t see how we actually hook the slider UI to the slider object so that it gets its value when we change the volume in the game.

Rick’s slider UI looks hooked OK but not mine… did I miss something or it wasn’t shown?

You can create a method that change volume with incoming argument float.
You dont need to do it in update.
Then something like this:
[SerializeField] Slider volSlider;

void ChangeVolume(float val){
AudioListener.volume = val;
//some code to save in player prefs
}

void Start(){
volSlider.onValueChanged.AddListener(ChangeVolume);
}

Thank you for the response and the solution.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms