Hi
Im trying to make a local high score system. At the moment the players score goes up from the Time.deltaTime and from collection powerups.
What i need is for when the player dies the score is saved as the highscore if it is higher than the last high score.
I have this code on the main camera in game:`float playerScore = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
playerScore += Time.deltaTime;
if (PlayerPrefs.GetInt ("highScore") >= playerScore ) {
PlayerPrefs.SetInt ("highScore", ((int)playerScore));
}
}
//good powerups!
public void IncreaseScore(int amount){
playerScore += amount;
}
//bad powerups!
/*public void DecreaseScroe(int amount){
playerScore -= amount;
}*/
void OnDisable(){
PlayerPrefs.SetInt ("Score", (int)( playerScore * 100));
}
void OnGUI(){
GUI.skin = guiSkin;
GUI.Label(new Rect(Screen.width * (4f/6.55f),Screen.height * (0.1f/6.3f),Screen.width * (5f/6.55f), Screen.height * (1f/6.3f)), "Score: " + (int)(playerScore * 100));
}`
And this one on the game over menu:`int score = 0;
int highScore = 0;
public GUISkin guiSkin;
void Start(){
score = PlayerPrefs.GetInt ("Score");
highScore = PlayerPrefs.GetInt ("Score");
}
public void OnGUI(){
//HUDScript hudScript = GetComponent<HUDScript>;
GUI.skin = guiSkin;
if(GUI.Button (new Rect(Screen.width * (1f/6.55f),Screen.height * (4f/6.3f),Screen.width * (1f/6.55f), Screen.height * (1f/6.3f)), "Level Select")){
Application.LoadLevel("StorySelect");
}
GUI.Label (new Rect(Screen.width * (1f/6.55f),Screen.height * (2f/6.3f),Screen.width * (5f/6.55f), Screen.height * (2f/6.3f)), "Score: " + score);
GUI.Label (new Rect(Screen.width * (3f/6.55f),Screen.height * (2f/6.3f),Screen.width * (5f/6.55f), Screen.height * (2f/6.3f)), "Highscore: " + highScore);
`