Saving score and getting score using PlayerPrefs

I’m having trouble getting this code to work… this snippet of script below is attached to my player;

var cacheScore:int;
var newScore:int;
cacheScore += Time.deltaTime;
PlayerPrefs.SetInt(“newScore”,cacheScore);

Here is the full script below which is attached to my Main Camera in my localscore scene. I’m on Unity iphone paid version, trying to test on my iphone to no avail (and in the Game mode). Score always shows 0 even though I play, get a score of say 10 and it goes to the localscore scene fine… any ideas? Much appreciated with any help, since I’m going a bit mental on this… :slight_smile:

#pragma strict
var showScore: int;
var scorestyle : GUIStyle;

function Start(){
var showScore = PlayerPrefs.GetInt(“newScore”).ToString();
}

function OnGUI()
{
GUI.Label(Rect(Screen.width / 2 - 100, 200, 400, 25), "Your Score: " + showScore,scorestyle);
}

showScore is an integer variable and PlayerPrefs.GetInt() returns integer value. But since you are using ToString(); function it is trying to convert to string. Remove the ToString() part from the Start().

Thanks so much Razor for looking at this code. Appreciate the help. Further to your change, I also had to remove “var” from the Start() function first line - working code is now below. :slight_smile:

#pragma strict
var showScore: int;
var scorestyle : GUIStyle;

function Start(){
showScore = PlayerPrefs.GetInt(“newScore”);
}

function OnGUI()
{
GUI.Label(Rect(Screen.width / 2 - 100, 200, 400, 25), "Your Score: " + showScore,scorestyle);
}