Hey guys Im stumped on how to save high scores. After my player gets killed and he has the highest score I want his score to be saved. I know I use PlayerPref class but im not sure how to use this.
static var score = 0; //current score
var totalScore = 0; //combined total of players score
var highscore = 0; //highest score player has gotten
var scoretext : GUIText;
var money : AudioClip;
function Update()
{
scoretext.text = score + ""; //display score
if(score > highscore && TurnGameOver.dead2 == true) //when player dies set highscore = to that score
{
highscore = score;
PlayerPrefs.SetInt("High Score", highscore);
Debug.Log("High Score is " + highscore );
}
}
function OnTriggerEnter(other : Collider)
{
//add to players score if he collects a gem
if(other.gameObject.name == "GreenGem" || other.gameObject.name == "BlueGem" || other.gameObject.name == "RedGem" ||
other.gameObject.name == "GreenGem(Clone)" || other.gameObject.name == "BlueGem(Clone)" || other.gameObject.name == "RedGem(Clone)")
{
score += 10;
Debug.Log("Your score is " + score);
Destroy(other.gameObject); //Destroys Gem after player collects it
}
}