- Home /
This question was
closed Feb 16, 2017 at 09:14 PM by
Verzus for the following reason:
The question is answered, right answer was accepted
Question by
Verzus · May 28, 2012 at 12:52 PM ·
c#androidplayerprefssaving
PlayerPrefs not saving
I am fairly new to the concept of PlayerPrefs and have been trying it around so that I would be able to save progress and settings.
While trying to set it up to save what controls the player want to use it doesn't seem to want to save it more then locally.
Please have a look at the code and see if you can find the problem.
Also I don't really think it's relevant but my target build is Android.
Relevant code written in C#.
public GUIStyle guiStyle;
public int joystick;
void start()
{
refreshJoystickState();
}
private void refreshJoystickState()
{
joystick = PlayerPrefs.GetInt("Joystick");
}
private void saveJoystickState()
{
PlayerPrefs.SetInt("Joystick", joystick);
}
void OnGUI ()
{
if (joystick == 1)
{
if(GUI.Button(new Rect(Screen.width / 2 - -200, Screen.height / 2 + 150, 150, 60), "Joystick is active"))
{
joystick = 0;
saveJoystickState();
}
}
if (joystick == 0)
{
if(GUI.Button(new Rect(Screen.width / 2 - -200, Screen.height / 2 + 150, 150, 60), "Accelerometer is active"))
{
joystick = 1;
saveJoystickState();
}
}
}
}
Thanks in advance. Verzus
Comment
Best Answer
Answer by whydoidoit · May 28, 2012 at 01:02 PM
Your Start function has a lowercase "s" and isn't being called. Otherwise it's fine
Haha, such a simple and obvious mistake. Thanks for the help