- Home /
Question by
Waltari · Jul 04, 2015 at 12:33 PM ·
javascriptbutton
UnityScript set button text
I am trying to set the text of a button programmatically that I made in UnityScript. This is way harded than it should be.
Here is my UnityScript code:
#pragma strict
var loginButton : UnityEngine.UI.Button;
function Start () {
var canvas = new GameObject ("canvas", Canvas);
var instance : UnityEngine.UI.Button = Instantiate(loginButton);
instance.GetComponent<GUIText>().text = "login"; // doesnt work
instance.transform.position = Vector2(0,0);
instance.transform.SetParent(canvas.transform);
}
Comment
Best Answer
Answer by jenci1990 · Jul 05, 2015 at 06:56 AM
instance.GetComponentInChildren<UnityEngine.UI.Text>().text = "login";