Hi,
I assign the text element in the inspector as shown.
However, when I run the game, the inspector looks like this.
I get a “NullReferenceExecption: Object Reference not set to an instance of an object”. Below is the code I am using.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ScoreKeeper : MonoBehaviour {
public Text scoreText;
public static int score;
// Use this for initialization
void Start () {
scoreText = gameObject.GetComponent<Text> ();
score = 0;
}
// Update is called once per frame
void Update () {
scoreText.text = "Score: " + score.ToString();
}
}