I keep getting this error on a score counter script for a game that I am makingthe score counter works but this error is just annoying and I dont want ot publish it with the errors stacking up.
Error:
NullReferenceException: Object reference not set to an instance of an object
ScoreCounter.Update () (at Assets/ScoreCounter.cs:26)
Script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class ScoreCounter : MonoBehaviour
{
public static int score; // The player's score.
public Text text; // Reference to the Text component.
void Start ()
{
// Set up the reference.
//text = GetComponent <Text> ();
// Reset the score.
score = 0;
}
void Update ()
{
// Set the displayed text to be the word "Score" followed by the score value.
text.text = "Score:" + score;
}
}