Getting trouble in using playerpref

I am trying to use the “roll- a-ball” example to testing the “playerprefs” class but no luck.

my idea is using the “playerprefs” to store how many time the ball drop into the black hole. However, the data is reset to 0 after exiting the games.

Here is my code:

var scoreDisplay : GUIText;
var LastScore : GUIText;
var score : int = 0;

function OnTriggerEnter (other : Collider)
{
other.gameObject.active = false;
score += 1;
scoreDisplay.text = "SCORE: " + score;

PlayerPrefs.SetInt (“Saved Var”, score);
var theVarToSave: int = PlayerPrefs.GetInt (“Saved Var”);
LastScore.text = "LastScore: " +theVarToSave ;
yield new WaitForSeconds (5);

other.gameObject.active = true;

}

Can anybody give me a walkthrough?

thanks!!

You need to get the value of your saved var in the Start() function in order to stop overwriting it.

Just do a score = PlayerPrefs.GetInt(“Saved Var”) somewhere in a Start() function.

Otherwise, the score var will always reset itself to zero.

thanks nvarcha!
it’s work