I’m trying to have a highscore in the same script with the current score, but I can’t get past the “Object reference not set to an instance of an object” error.
There is something wrong with the score.text = "Score " + scoreValue; says it returns nothing.
Maybe is that it starts with 0. It’s not a normal score, it’s somewhat special, the score increases when an enemy gets killed, and enemies give a certain number.
I need help.
public Text Highscore;
public static int scoreValue = 0;
Text score;
void Start()
{
score = GetComponent<Text>();
Highscore.text = "Highscore " + PlayerPrefs.GetInt("Highscore", 0).ToString();
}
void Update()
{
score.text = "Score " + scoreValue;
{
if (scoreValue > PlayerPrefs.GetInt("Highscore", 0))
{
PlayerPrefs.SetInt("Highscore", scoreValue);
}
Highscore.text = scoreValue.ToString();
}
}
}