- Home /
Question by
markruseev · Jun 14, 2014 at 12:48 PM ·
2dscoresaving
HighScore doesn't work
Please help! When I play highscore always equials score. What's wrong?
using UnityEngine;
using System.Collections;
public class Score : MonoBehaviour {
public GUIText scoreText;
public GUIText scoreText1;
public GUIText bestScore;
public int scoreValue;
private int score;
private int highscore = 0;
void Start () {
score = 0;
PlayerPrefs.GetInt ("HighScore");
UpdateScore ();
}
void OnCollisionEnter2D () {
score += scoreValue;
UpdateScore ();
}
void UpdateScore () {
if (score > highscore) {
highscore = score;
PlayerPrefs.SetInt ("HighScore", highscore);
}
scoreText.text = "" + score;
scoreText1.text = "" + score;
bestScore.text = "" + highscore;
}
}
Comment
Answer by LMan · Jun 14, 2014 at 01:04 PM
Well it seems that you are getting the highscore from playerprefs in start without putting that value into anything. Try:
highscore = PlayerPrefs.GetInt ("HighScore");