I’m making a little endless runner game where the camera follows a moving character. I managed to make the score gui work but for some reason my highscore gui doesn’t keep track of the highest score and just displays 0 all the time. I’m new to coding but have some experience with how unity works, I feel like i’m just overlooking something very simple but haven’t been able to find answers online.
Here is my code for managing the score/highscore:
using UnityEngine;
using System.Collections;
public class NewScore : MonoBehaviour {
static int score = 0;
static int highScore = 0;
static public void AddPoint() {
if(score > highScore) {
highScore = score;
}
}
void Start() {
score = 0;
highScore = PlayerPrefs.GetInt("highScore", 0);
}
void OnDisable() {
PlayerPrefs.SetInt("highScore", highScore);
PlayerPrefs.SetInt ("score", score);
}
void Update () {
guiText.text = "Score: " + score + "
High Score: " + highScore;
PlayerPrefs.SetInt (“highScore”, highScore);
}
public void IncreaseScore(float amount)
{
score += (int)amount;
}
}