Question by
voldiemort · Mar 07, 2016 at 10:29 AM ·
scripting problembutton
Trying to change text of button using script
I'm trying to change the text of my button using the game controller script (obviously) so here's what I'm doing:
My button is called "Button 1"
In my script I do:
public text buttonOne
void Start(){
buttonOne = GameObject.Find("Button 1").GetComponent<Text>();
}
void Update(){
...
buttonOne.text = "Buy";
}
But the text doesn't change. Thanks for the help in advance :3
Comment
Best Answer
Answer by Ali-hatem · Mar 07, 2016 at 11:00 AM
public text buttonOne;//just attach the button text to this script by drag & drop .
void Start()
{
buttonOne.text = "Buy";
}
Thanks a lot! :D Just curious though, why doesn't the method above work?
you mean your method i think because there is no text component in the button it's just a child game object so you have to deal with this child object.