Hi all, I’m newbie in Unity 4.6
I use canvas for my UI, and inside the canvas I have an image has text. I want to show the game score that change periodically on that text.
How I do that? I mean how I access the text in the image and change it via script? I already read the topic [4.6 - UI] Changing the text component via script? - Unity Answers , but I still can’t get the answer, I hope someone can solve this. Many thanks!
Create a public GameObject variable in one of your scripts, and then drag the gameobject containing the Text component into that variable in the inspector.
public GameObject textgameobject;//set this is inspector or by script, maybe GameObject.Find or something, idk.
Text text = textgameobject.GetComponent<Text>(); //get the text component in the gameobject you assigned
text.text = "insert some text here"; //set the text in the text component
Hey i’ve solved the same problem but a little diffrent now (12 juli 2017).
Instead of GetComponent< Text>(). I had to use Getcomponent< GUIText>().
The rest is exactly the same as @Erisat’s