- Home /
I can't access a values of UIText Component
I have Unity 5, and I want access by script the UIText component there is in a GameObject. However, not there is "GetComponent ();", just there is "GetComponent ();" and not is same Component that UIText there is in a GameObject. (I'm sorry for my English)
Comment
yourUIGameobject.getComponent<YOUR_SCRIPT>().YOUR_PUBLIC_FUNTION();
Answer by Nikunj-Kareliya · Sep 07, 2015 at 08:36 AM
You can do by adding,
GetComponent<Text >().text = "your_text_here";
Make sure you've imported UI namespace at start of the script.
using UnityEngine.UI;
If you wanna access UI Text which is on another gameobject, then use like this:
otherGameobject.GetComponent<Text >().text = "your_text_here";
Answer by RafiXWPT · Sep 07, 2015 at 08:29 AM
If you want to access to "text" inside UIText:
yourGUITextObj.GetComponent<Text>().text = "something";
string somethingElse = yourGUITextObj.GetComponent<Text>().text;
Just add using Unity.UI at start.