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 timshaya · Mar 28, 2012 at 11:26 PM · textguitextfontresources.loadaddcomponent

How do I create GameObject & add GUIText from script for iOS?

I'm trying to add a GUIText component via code only but it fails to show up on screen.

My Platform is set to iOS in Build Settings. I have a super basic empty Scene with a Camera. The Camera has a very simple script attached to it. I'm using Unity 3.5 iOS Pro trial. A font called "HelveticaNeueLTStd-Md" is inside a Fonts folder in my Project panel. The font is set to "ASCII default set" in the Inspector. Other scripts in the project are using this font in a GUIskin (which exists in the Project panel).

The Awake() function for my problem script has this:

 //load font from the Project view in the Unity IDE
 var font1:Font = Resources.Load('Fonts/HelveticaNeueLTStd-Md');

 var go1:GameObject = new GameObject('GUITextObj1'); 
 go1.AddComponent('GUIText');
 go1.guiText.font = font1;
 go1.guiText.transform.position = new Vector3(0, 0, 0);
 go1.guiText.material.color = Color.white;    
 go1.guiText.text = 'Some temp text for now'; 

 Debug.Log("go1.guiText.text = " + go1.guiText.text);
 Debug.Log("go1.guiText.transform.position = " + go1.guiText.transform.position);     

There are no physical copies of "go1" anywhere else, since I'm just trying to create it via code.

When I hit the Play button GUITextObj1 shows up in the Hierarchy panel, the Console shows the Log values.

However, the text is not showing up on screen in the Game panel.

Does anyone have any idea of what I'm doing wrong?

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
0

Answer by IRobb · Jun 07, 2014 at 02:44 PM

Try go1.guiText.transform.position = new Vector3(0.5f, 0.5f, 0);

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to display Greek alphabets 0 Answers

Canvas Text gets garbled 0 Answers

How can I display ligatures? (in TextMesh and/or GUIText) 0 Answers

How do I create a gui text component using c# script? 1 Answer

GUIText doesnt show after changing font 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