(Issue is open on GitHub Here)
I am building a health bar for a fighting game in Unity, and for some reason the Health bar text does not appear and all it gives me is a null reference error, yet I've checked that everything it references is not 'null'.
The code for the text is here:
function Update () {
canvasText.text = brawlers[0].currentHealth + "/" + brawlers[0].myClass.health;
canvasText2.text = brawlers[1].currentHealth + "/" + brawlers[1].myClass.health;
}
The Brawlers array refers to two classes, each of them like this:
#pragma strict
var className : String;
var health : int;
var Attack : int;
var Defense : int;
var Speed : int;
I created a prefab with only the class attached and gave the health a value of 120. This prefab is attached to the fighters in the game, which are the brawlers array, as the 'myClass' varible. CurrentHealth is a varible initilized in the Brawler class.
I have tried multiple types to trace the parts that wouldn be null in the project but I have not found anything that could mean that this error is thrown.
Why is there a null reference exception then?