Hi
Im currently using this code to set a highscore for my player but the highscore number isnt displaying,the debug is working so the function is correct, anyone know what may be the problem or get a better solution?
public class Score : MonoBehaviour
{
private static int score;
public Text textscore;
public Text bestScore;
public GameObject Player;
void Start()
{
score = 0;
InvokeRepeating("ScoreUpdate", 1f, 1f);
}
void Update()
{
textscore.text = "Score: " + score;
bestScore.text = "HighScore: " + PlayerPrefs.GetInt("bestscore");
// + PlayerPrefs.GetInt("bestscore");
}
void ScoreUpdate()
{
if (Player)
{
score += 1;
int highscore = PlayerPrefs.GetInt("bestscore", 0);
if (score > highscore)
{
PlayerPrefs.SetInt("bestscore", score);
Debug.Log("set highscore");
}
}
}
}