- Home /
GUIText component won't render
In my script I create a new GameObject and attach a GUIText component to it with necessary configuration but for some reason it won't render.
Here is my code:
public class GameGUI : MonoBehaviour {
public GameObject stepsTextObject;
void Awake(){
this.stepsTextObject = new GameObject("StepsText");
this.stepsTextObject.transform.parent = this.transform;
this.stepsTextObject.AddComponent<GUIText>();
this.stepsTextObject.transform.position = new Vector3(0.5f, 0.5f, 0);
this.stepsTextObject.guiText.font = new Font("Arial");
}
void Start(){
this.stepsTextObject.guiText.text = Game.playerComponent.steps.ToString();
}
void Update(){
this.stepsTextObject.guiText.text = Game.playerComponent.steps.ToString();
}
}
Answer by revolute · Oct 08, 2014 at 03:20 AM
Your problem is that you make a new Font.
Just delete new Font() and it will work. It will use a default font.
Thanks. This is it. I have another question though: What if I have a font I want to use other than the default one. How do I change it then?
You can use Resources.Load() to load items in resource folder
Your answer
Follow this Question
Related Questions
How to disable a custom script in a custom GameObject with C# ? 2 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Trying to Highlight text in order to copy and paste, but do not want the text to be editable. 1 Answer
Can EditorWindows dynamically display interfaces of other Editor Windows ? 1 Answer