Hey all im doing my first attempt at a playerPref highscore system and have run it to a little problem.
The problem is :
Argument Exception: GetString can only be called from the main thread.
I have googled the problem and i understand it has to do with code being outside of a function but i cannot work it out. Here is my code,
PlayerPrefs.GetString("RecordName",String.Empty);
PlayerPrefs.GetInt("RecordScore", -1);
function GetScore(recordIndex :int) :int
{
var key = String.Format("RecordScore", recordIndex);
return PlayerPrefs.GetInt (key, -1);
}
function SetScore (recordIndex:int,score:int)
{
var key = String.Format("RecordScore",recordIndex);
PlayerPrefs.SetInt(key,score);
}
function GetName (recordIndex:int):String
{
var key = String.Format("RecoerName", recordIndex);
return PlayerPrefs.GetString(key,String.Empty);
}
function SetName(recordIndex:int,name:String)
{
var key = String.Format("RecordScore",recordIndex);
PlayerPrefs.SetString(key,name);
}
var topName = GetName(0);
var topScore = GetScore(0);