Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

How to Fix NullReferenceException: Object reference not set to an instance of an object (JS)

$
0
0
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.

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>