I am working on a game and need to display the players health via UI. I am getting an error message when I enter play mode though and the health does not update. The error message that I am getting says: “NullReferenceException: Object reference not set to an instance of an object”. What does this mean and how do I fix it?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ScoreUpdate : MonoBehaviour {
public Text score;
public int points;
public int life;
public Text lifecount;
public Controls controls;
// Use this for initialization
void Start ()
{
//This is a separate script attacted to the player that contains the health variable for the player
controls = GetComponent<Controls>();
}
// Update is called once per frame
void Update ()
{
score.text = "Score: " + points.ToString();
life = controls.health;
lifecount.text = "Health: " + life.ToString();
}
}