- Home /
GUIText update error
GUITextUpdate.js
private var numPoints= 0;
function Start()
{
UpdateDisplay();
}
function UpdateDisplay()
{
guiText.text = "Points: "+numPoints;
}
function AddPoints()
{
numPoints++;
UpdateDisplay();
}
DetectCollision.js
var gu: GUITextUpdate;
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Wicket"){
Debug.Log("Hit the cube");
gu.AddPoints();
}
}
giving this error
NullReferenceException: Object reference not set to an instance of an object DetectCollission.OnCollisionEnter (UnityEngine.Collision theCollision) (at Assets/Script/DetectCollission.js:6)
Comment
Answer by Berenger · Jun 18, 2012 at 04:49 AM
You need to assign gu at some point, the inspector is probably the best way for you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072921im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Score Not Adding Up..? 1 Answer
Update Gui Text with Score 2 Answers
Saving Highscore 2 Answers
Calling Enemy Health Adding to Player Score 0 Answers
How to add the right amount of points when my player destroys a gameobject? 0 Answers