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
0
Question by Nanako · Dec 07, 2014 at 05:11 AM · guitextfont-size

What is needed for a GUIText component?

I'm trying to, from a script added to an otherwise empty object, create a GUIText component, and write text to it.

I've got the AddComponent working fine, but that's about as far as i've gotten. After that i've been hitting play and experimenting with things in the inspector, to figure out what i have to do.

So far i've tried typing "test" in the text field, assigning FontMaterial to the material slot, assigning arial as the font, setting the font size to 10, setting the anchor to middle center, setting the pixel offset to zero, and setting the font colour to black

I would think that all of these things would be enough to get things going, and m,ake the word "test" appear in the middle of the screen in black letters , but i still cannot make any text appear onscreen.

any idea what i might be missing? What steps are needed to make this work?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Vurawid · Dec 07, 2014 at 05:25 AM

The GUIText component uses viewport space and the initial position usually puts it offscreen. Doing the following may help to get started and better understand.

  1. Create an empty GameObject

  2. Add a GUIText component to it

  3. Set the X to 0.5

  4. Set the Y to 0.5

  5. Change the text to "test"

  6. Switch to the game view window

Here is a video from the Unity Space Shooter tutorial that I found useful to learn more about GUIText... Space Shooter Project: Counting Points and Displaying the Score

Edit: Adding some code that creates a GUIText component in center of view with text "Hello World".

 GameObject myGameObject = new GameObject ();
 myGameObject.transform.position = new Vector3(0.5f, 0.5f, 0f);
 GUIText myComponent = myGameObject.AddComponent<GUIText> ();
 myComponent.text = "Hello World";
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
avatar image Nanako · Dec 07, 2014 at 07:30 AM 0
Share

thank you my friend <3 i figured ou the problem of the XY position shortly after posting this, but i was still stuck on the subsequent requirement that i couldn't actually then have the text component on the object itself.

i've never actually created gameobjects in code like that,forgot it could be done. Thank you, this will work well.

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

27 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

Related Questions

GUIText position changes with changing resolution 2 Answers

Add text on top of a gameobject. What is the best way? 1 Answer

GUItext works 1 of 3 situations? 0 Answers

Draw GuiText on 2d tile sprite Like 2048 game 0 Answers

Display GUI Text 1 Answer


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