Hi, I am trying to access the text on a Button in Javascript. The text is in a button called Button1 on a Canvas set to worldspace. I can’t find a way to get or set the text in code?
Any help appreciated
Hi, I am trying to access the text on a Button in Javascript. The text is in a button called Button1 on a Canvas set to worldspace. I can’t find a way to get or set the text in code?
Any help appreciated
public Text Score;
int score = 10;
void Start ()
{
Score.text = score.ToString ();
}
Hi BoredMoron,
Thanks for pointing out that Josh misread when stated that I need javascript. Anyway this is what I think the translation to javascript is:
#pragma strict
public var Score:UnityEngine.UI.Text;
var score:int = 10;
function Start ():void
{
Score = GetComponentInChildren(UnityEngine.UI.Text);
print( "score= "+ Score.text);
Score.text = score.ToString ();
}
I was going wrong with the type in GetComponentInChildren(UnityEngine.UI.Text);
didn’t realize I needed the full path to the object type and was just using (Text);
thanks for your input guys!