This script manages the Audio volume of various sounds and music, and saves the audio levels to be loaded later when the game is restarted.
Start();
On start up this script will look for the saved player Preference keys related to each of the the volume settings for Music, Sound effects, and the Master volume control, this is so players don't need to change the volume for each sound type every time the game is started up, if there is no save settings it will load the default audio settings
SetMusicVolume() SetSfxVolume() and SetMasterVolume()
float volume(type) = (type)Slider.value;
This gets the slider value
myMixer.SetFloat("(Type)"
This makes the float of each volume type is equal to the UI slider's value, making the slider control the volume level when the player adjusts the sliders. setting the parameter of the audio mixer to the slider
The audio mixer volume changes Logarithmically but the value of the slider changes Linearly "Mathf.Log10(volume(type)*20)" gets the Logarithmic value of the slider and multiplies it by 20, making the UI slider when adjusted alter the volume type on a one to one scale.
LoadVolume()
This is where each audio types value are being saved using "PlayerPrefs.GetFloat("(Type)Volume");"
where it gets and saves the float value of the audio slider and mixer, to be later loaded when the game is started back up again.
Comments
Post a Comment