I'm using a textmesh to check variables in real time. Thing is if I use AddComponent within Update(), it obviously starts spamming and slows the game. If I try with GetComponent the error is the following:
NullReferenceException: Object reference not set to an instance of an object
DebugCombo.Update() (at Assets/DebugCombo.js:9)
which points to the text.text
assignment.
This is the script from DebugCombo.js, from which I call the Combo class (from Combo.js)
#pragma strict
public class DebugCombo extends MonoBehaviour{
function Update () {
var text = gameObject.GetComponent(TextMesh);
var combo = gameObject.GetComponent(Combo);
text.text = "Current: "+ Time.time +" | Limit: " + combo.comboTime;
}
}
How do I get rid of this error?
var text:TextMesh = gameObject.GetComponent(TextMesh);
andvar combo:Combo = gameObject.GetComponent(Combo);
. Does this fix it? \$\endgroup\$