Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by VAN-D00M · Jan 09, 2015 at 08:21 PM · textcanvas

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

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mmmpies · Jan 09, 2015 at 08:32 PM 0
Share

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";
avatar image Mexallon · Jan 09, 2015 at 08:33 PM 0
Share

@$$anonymous$$mmpies is right. You need to use "Text" as "GUIText" is part of the old Unity GUI system

avatar image VAN-D00M · Jan 09, 2015 at 08:37 PM 0
Share

Oh so simple. Had no idea the data type had changed. Thank you @$$anonymous$$mmpies and @$$anonymous$$exallon

avatar image DanSuperGP · Jan 09, 2015 at 08:38 PM 0
Share

It's also in a different namespace, so you have to add

Using UnityEngine.UI;

At the top of your file.

avatar image Priyanshu · Jan 09, 2015 at 08:39 PM 0
Share

$$anonymous$$ake sure you have "using UnityEngine.UI;" at the top of your script.

1 Reply

· Add your reply
  • Sort: 
avatar image
7

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;

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges