- Home /
Playerprefs not saving
Hello,
Im trying to make a script to save the player settings like volume and field of view.It used to work before but it suddenly stopped for some reason.This is the script Im using(a part of it actually) :
var FOV : float = 75;
var mainCamera : Camera;
var bulletCamera : Camera;
var field = PlayerPrefs.GetFloat("FOW");
var velume : float = 1;
var valume = PlayerPrefs.GetFloat("Volume");
var player : Transform;
function Awake()
{
FOV = field;
velume = valume;
}
function OnGUI ()
{
GUI.skin = myGUISkin;
if (menu1==true)
{
if (GUI.Button(Rect(Screen.width/2.5,Screen.height/2.03,Screen.width/5,Screen.height/10),"Field Of View: " + FOV.ToString("f0")))
{
}
FOV = GUI.HorizontalSlider (Rect ( Screen.width/2.5,Screen.height/1.7, Screen.width/5, Screen.height/10), FOV, 50, 150);
mainCamera.fieldOfView = FOV;
bulletCamera.fieldOfView = FOV;
Camera.main.fieldOfView = FOV;
PlayerPrefs.SetFloat("FOW", FOV);
PlayerPrefs.Save();
if (GUI.Button(Rect(Screen.width/2.5,Screen.height/1.65,Screen.width/5,Screen.height/10),"Volume: " + velume.ToString("f0")))
{
}
velume = GUI.HorizontalSlider (Rect ( Screen.width/2.5,Screen.height/1.4, Screen.width/5, Screen.height/10), velume, 0, 10);
player.audio.volume = velume / 10;
PlayerPrefs.SetFloat("Volume", velume);
PlayerPrefs.Save();
}
}
This is the player script(a part of it) :
var pauseMenu : PauseMenu;
var valume : PauseMenu;
function Start()
{
pauseMenu = GetComponent(PauseMenu);
audio.volume = pauseMenu.valume;
Camera.main.fieldOfView = pauseMenu.FOV;
}
Now the volume won't even change anymore with the slider.This is really frustrating.It worked before, I don't remember making any changes to it. Any little help would be really appreciated.
Thank you for your time.
There might be a problem with the way your playerprefs were stored. Delete them and see if it works after
PlayerPrefs.DeleteAll();
Or you might have other playerprefs you don't want deleted so do
PlayerPrefs.Delete$$anonymous$$ey("Volume");
PlayerPrefs.Delete$$anonymous$$ey("FOW");
PlayerPrefs has a size limit. Could it be that it's full?
Neither of the options you gave me worked. When you say that PlayerPrefs has a size limit, how can I actualy know when it's full. I only have 2 playerprefs by the way, the ones shown on the main question.
The PP size limit on WebPlayer builds is 1$$anonymous$$B, and you'll know you hit it if SetFloat
and friends start throwing a PlayerPrefsException
.
Currently, you're running those GetFloat
calls using field initializers. Those sometimes cause problems if they're run during the scene load. You might try moving them to Awake
to see if that helps.
Answer by Ssiroo · Jul 31, 2014 at 04:48 PM
I replaced this line :
player.audio.volume = velume / 10;
with this one :
AudioListener.volume = velume;
And it somehow worked.
Also I replaced these lines :
var field = PlayerPrefs.GetFloat("FOW");
var velume : float = 1;
var valume = PlayerPrefs.GetFloat("Volume");
var player : Transform;
function Awake()
{
FOV = field;
velume = valume;
}
with these :
var FOV : float = 75;
var mainCamera : Camera;
var bulletCamera : Camera;
var velume : float = 1 / 10;
var player : Transform;
function Awake()
{
FOV = PlayerPrefs.GetFloat("FOW");
velume = PlayerPrefs.GetFloat("Volume");
}
Thank you everyone for trying to help me, I really appreciate it!