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?

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";