i dont understand why im getting this problem, here’s my script
public class Pause : MonoBehaviour {
public Text label;
public DistanceSystem anotherScript;
// Use this for initialization
void Start () {
}
void Awake(){
anotherScript = GetComponent<DistanceSystem> ();
}
// Update is called once per frame
void Update () {
label.text = anotherScript.distanceTravelled.ToString ("F0");
}
i dragged the text that the distancesystem is attached to it as the public distancesystem anotherscript, and label is the text i want to display the score at
distance system looks like this
public Transform player;
public Text label;
public float distanceTravelled;
float lastPosition;
void Start () {
lastPosition = player.transform.position.y;
}
// Update is called once per frame
void Update () {
distanceTravelled = player.transform.position.y - lastPosition;
label.text = distanceTravelled.ToString ("F0")+"m";
}
which works fine, just when i press pause it doesn’t print it where i want it and returns the error in the title
Reading questions tagged with NullReferenceException is always a good plan. I'd have closed this as a duplicate if your question didn't already have an answer.
– Graham-Dunnett