Hello, I’m trying to get my score to update when my enemy is destroyed, but I keep getting a NullReferenceException: Object reference not set to an instance of an object error. I have the following HealthScript attached to my enemy:
public void Damage(int damageCount)//Inflicts damage
{
hp -= damageCount;
if (hp <= 0) {
ScoreScript score = GetComponent<ScoreScript> ();
score.UpdateScore (5);
Destroy (gameObject); //destroy enemy
}
}
Then, I have the following ScoreScript attached to my player:
public void UpdateScore(int scoreToAdd){
score += scoreToAdd;
}
The “score” is a public static int and seems to be recognized as such. What am I doing wrong?