i finally got player prefs to work, but unity insists that there is a problem, actually three. I made it so it saves the value of a variable, gold. it works, but it says a bunch of wierd problems. Heres the script with the gold variable:
function Start()
{
if(!PlayerPrefs.HasKey("Gold"))
{
static var gold : int = 0;
PrefsScript.saveIntPref("Gold",gold);
}
else
{
PrefsScript.loadIntPref("Gold",gold);
}
}
function OnGUI()
{
GUI.Label(Rect(1300,20,100,50), "Gold: " + PlayerPrefs.GetInt("Gold"));
if (GUI.Button(Rect(5,80,80,50), "Pause"))
{
if(Time.timeScale > 0)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
if (GUI.Button(Rect(5,15,80,50), "Main Menu"))
{
Application.LoadLevel(0);
}
}
function Update()
{
PrefsScript.saveIntPref("Gold",gold);
}
and here's the script with the PlayerPrefs functions:
static function saveIntPref(key,variable)
{
PlayerPrefs.SetInt(key,variable);
}
static function loadIntPref(key,variable)
{
variable = PlayerPrefs.GetInt(key);
}
static function saveFloatPref(key,variable)
{
PlayerPrefs.SetFloat(key,variable);
}
static function loadFloatPref(key,variable)
{
variable = PlayerPrefs.GetFloat(key);
}
static function saveStringPref(key,variable)
{
PlayerPrefs.SetString(key,variable);
}
static function loadStringPref(key,variable)
{
variable = PlayerPrefs.GetString(key);
}
static function killPref(key)
{
PlayerPrefs.DeleteKey(key);
}