- Home /
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?
Answer by IRobb · Jun 07, 2014 at 02:44 PM
Try go1.guiText.transform.position = new Vector3(0.5f, 0.5f, 0);
Your answer
Follow this Question
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