- Home /
How do you reference a Text on a Canvas - Unity 4.6 GUI
Hi
I'm trying to reference text that is on a canvas using this new GUI with Unity 4.6.
I've done what you would usually do. Create a public GUIText variable in the script, drag it from the hierarchy and drop it in the inspector but it won't let me do this with text that is on a canvas. Any ideas what your supposed to do?
public GUIText highscoreText;
Cheers people :)
file:///Applications/Unity/Unity.app/Contents/Documentation/html/en/Manual/script-Text.html
Have you tried just using Text as in:
public Text highscoreText;
That needs to then reference the text element of Text like this:
highscoreText.text = "Whatever you want in here";
@$$anonymous$$mmpies is right. You need to use "Text" as "GUIText" is part of the old Unity GUI system
Oh so simple. Had no idea the data type had changed. Thank you @$$anonymous$$mmpies and @$$anonymous$$exallon
It's also in a different namespace, so you have to add
Using UnityEngine.UI;
At the top of your file.
$$anonymous$$ake sure you have "using UnityEngine.UI;" at the top of your script.
Answer by DanSuperGP · Jan 09, 2015 at 08:35 PM
It's not a GUIText, it's
UnityEngine.UI.Text
So you need to either refer to it as so, or add the namespace to the using section at the top of your script.
Using UnityEngine.UI;
public Text highScoreText;
Your answer
Follow this Question
Related Questions
How To Show 2d Text After Collision (3D Game btw) 0 Answers
Canvas Button persistence 0 Answers
Text smaller on higher resolution screen than on lower resolution screen 1 Answer
Finding a GameObject using a canvas text? 2 Answers
Unity UI Text with markup tags - “String too long for TextMeshGenerator” 0 Answers