Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Trying to get javascript to chnge UI.text but it wont

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

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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