Hi, I’m really new to coding in JavaScript. I am trying to make a game where you kick a tree (yeah, stupid) and whenever your leg collides with it, it scores a point. But I’m getting this error: NullReferenceException: Object reference not set to an instance of an object
Here is my code for the tree:
var Counter : int = 0;
function Update () {
textField = GetComponent(UI.Text);
textField.text = "Score: "+Counter;
}
function React () {
Counter++;
}
And here is my code for the leg:
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Target"){
gameObject.Find("Score").SendMessage("React");
Debug.Log("Score!");
yield WaitForSeconds(1);
gameObject.active=false;
}
}
So what is the problem? Thank you.