Hi all,
I simply want to have a counter for a variable which increases each frame.
I can’t figure out why this code won’t work: (JS)
var oofcounter : UnityEngine.UI.Text;
function Update () {
oofcounter.text = "OOFs: " + oofs.ToString();
}
“oofs” is the variable that changes every frame.
“oofcounter” is the name of the UI text as a game object.
Bip901
2
You didn’t really tell us what you mean by “won’t work”… [Do you get an error? Is the text not changing? Is the text not showing up?] but here are some possible fixes:
Make sure you have this line in the top of your code:
import UnityEngine.UI;
You also don’t need to write UnityEngine.UI.Text, just use the type “Text”:
var oofcounter : Text;
Don’t forget to drag the GameObject “oofcounter” into the slot of the variable “oofcounter” in the inspector, as well. You have to reference it.