I am trying to change the text field of a UI but it won't let me.
- I am using javascript
- There is a canvas and the text field is on the canvas.
- I have a variable 'textField' which is a UI.text on the script.
- I dragged the proper game object onto it.
- It gives an error when it tries to access the text field.
NullReferenceException: Object reference not set to an instance of an object
Score_js.Update () (at Assets/Scripts-JS/Scripts-GUI/Score_js.js:33)
///////////////////////////////////////////////////////
#pragma strict
import UnityEngine.UI;
///////////////////////////////////////////////////////
//VARIABLES
static var numHits:int = 0;
static var playerScore:int = 0;
var textField : UI.Text;
var str1:String = "";
///////////////////////////////////////////////////////
function Start()
{
if (playerScore < 0)
{
playerScore = 0;
}
str1 = playerScore.ToString();
textField = GetComponent(UI.Text);
textField.text = str1;
}
///////////////////////////////////////////////////////
function Update ()
{
if (playerScore < 0)
{
playerScore = 0;
}
str1 = playerScore.ToString();
textField = GetComponent(UI.Text);
textField.text = str1;
}
///////////////////////////////////////////////////////
![alt text][1]
![alt text][2]
[1]: /storage/temp/58096-capture.png
[2]: /storage/temp/58097-capture2.png
↧