I am working on a simple level loading scene, and am running into some issues using GUIText objects for labels over nodes the player can select. Currently I have my scene set up like this:
- 5 levelSelectNode game objects with a Sprite Renderer and a script (detailed below)
- Each levelSelectNode game object has a single child titled “nameLabel” with a GUIText component
The levelSelectNode script handles assigning a value to the child nameLabel GUIText text field. It also handles positioning the label so that it is always visible as the camera moves about the scene (to allow for panning around the level selection scene).
levelSelectNode script:
public string nodeName;
void Update () {
// Render name label
Camera mCam = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>();
transform.GetChild(0).GetComponent<GUIText>().pixelOffset = mCam.WorldToScreenPoint(transform.position);
transform.GetChild(0).GetComponent<GUIText>().text = nodeName;
}
I placed 5 of these prefab objects onto my scene, and assigned different nodeName values for each (on the parent). When I go to run the game, only the first object shows its name on the game screen. All the rest are missing their labels. However, if I inspect each of the other objects in the Scene view (while the game is running) I see the Text and Pixel Offset values are assigned correctly even though the values are not being represented in the game. Basically, they would appear to be set perfectly (when compared to the first node).
I’ve checked the MainCamera and culling is set to Everything. The clipping plane is set to 0-1000. I also attempted to change the pixelOffset to a generic (100,100) value - and when I did this, the first node showed it’s nameLabel at that location, but none of the others showed up (I expected them to all show up jumbled together at that location).
Is there something fundamental I’m missing when it comes to GUIText components? Am I limited to seeing only one at a time? I’d expect not, but I feel I’m missing something important.
Thanks in advance for any help you can provide!