Try to add the f
for float behind the 1.
PlayerPrefs.GetFloat(MASTER_VOLUME_KEY, 1f);
Given that the Start method in the OptionsController gets called before the SetMasterVolume method, the console should say “Master volume is 1”.
Double check the references. Does the volumeSlider
variable reference the correct slider in your game? Do the game objects have the relevant components attached? Does no other component/object call GetMasterVolume()? Add a Debug.Log to GetMasterVolume to see how often that method gets called.
For testing purposes, call PlayerPrefs.DeleteAll() in the Awake method of the OptionsController. Maybe you are just getting a value from the old PlayerPrefs file, which is stored somewhere on your harddrive. If there is a key named “master volume”, the GetFloat() method returns the value associated with that key, else 1f.