[SOLVED] PlayerPrefs.SetFloat not working

I am using Unity 5.5 and am getting the error ‘PlayerPrefs’ does not contain a definition for ‘SetFloat’. My code is as follows:
public static void SetMasterVolume (float volume)
if (volume > 0f && volume < 1f) {
PlayerPrefs.SetFloat(MASTER_VOLUME_KEY, volume);
} else {
Debug.LogError (“Master volume out of range”);
public static float GetMasterVolume () {
return PlayerPrefs.GetFloat (MASTER_VOLUME_KEY);

Please help.

This is really strange, since SetFloat is a method of the PlayerPrefs class. Did you check that you have using UnityEngine at the start of the script?

Please copy the script in its entirety, using the tags code-/code, and copy/paste the exact error that’s given by Mono.

Thank you for your reply. I went back over the script and realized that I had changed the script name in the very beginning from “PlayerPrefs” to “PlayerPrefsManager”. In doing so I inadvertently had a class name of “PlayerPrefs” and my script name was “PlayerPrefsManager”. I fixed it and now the problem is solved. I have to say I feel a bit silly making such a simple mistake but I guess it’s all part of the learning process. Thanks again for the reply.

I did the exact same thing! :blush:

I did that too - I created the script as “PlayerPrefs” but then heard Ben give the reasoning and changed it to “PlayerPrefsManager,” but the script didn’t update the class name along with the script name.

Privacy & Terms