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();
}
}
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?
– k9rosieYou can use Resources.Load() to load items in resource folder
– revolute