The way to do this is to have a variable you store somewhere globally. I did this with a playerprefs variable so that if I turned off the game and came back it would remember the volume I wanted.
So whenever they change the volume you determine what they changed it to and run this code:
PlayerPrefs.SetFloat("Volume", 0.75F);
The 0.75f in the above example would be whatever float they changed the volume to.
Additionally, whenever you load any screen with a volume bar on it you run this code:
float tempVolume = PlayerPrefs.GetFloat("Volume", 1.0F);
Instead of 1.0f in the above code you would put whatever you want the default volume to be. This code will return the volume that they set last time OR it will return the default volume if they have never set a volume.
Once you have run that code you just set your volume bar to the value of tempVolume.
↧