How to get the UI text to a variable?

So, I’m just trying to make it so I get the new UI text, to a string, how would I go about this? I’ve tried get component ( as seen below)

function Start () {
iptext = GetComponent("Text");
print(iptext);
}

with these results from printing it:

So, it seems to get it for a second… so, what am I doing wrong?

The Text component has a variable called “text” :wink: So you should do

print(iptext.text);

Btw, you should check if iptext is null, just in case.

1 Like

I get: “text” is not a member of unity engine Component.

You need to import UnityEngine.UI (I don’t know how you can do that in UnityScript).

Edit:

import UnityEngine.UI;
1 Like

Still getting the compiler error even after importing it.

Because you’re using a string with GetComponent, try this:

var iptext : Text;
iptext = GetComponent(Text);
1 Like

Thank you so much for walking me through this, usually I’m a bit more ready for the leap to something new but I just completely missed the jump on this one.