Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to make a series of text appear programmatically. It's not quite showing up, and I'm struggling to understand exactly why. Any ideas?

GameObject row = new GameObject("Row");
row.transform.parent = panel.transform;
HorizontalLayoutGroup rowLayoutGroup = row.AddComponent<HorizontalLayoutGroup>();
rowLayoutGroup.childForceExpandHeight = false;

GameObject name = new GameObject("Name");
name.transform.parent = row.transform;
GameObject value = new GameObject("Value");
value.transform.parent = row.transform;

Text nameText = name.AddComponent<Text>();
nameText.text = tup.First;
nameText.alignment = TextAnchor.MiddleRight;

Note that this script is run from a Panel, contained within a Canvas.

share|improve this question
    
We'll need to know more about how the GameObject called "name" is set up in your scene hierarchy. Right now it could be just about anything - maybe it's out of the camera frame, or sized too small to contain the text you're giving it, or culled by a mask, layer, active, or enabled setting somewhere in the chain... – DMGregory Jan 12 '16 at 2:11
    
@DmGregory I've added more information, however, I figured out the real problem, and that was that the font wasn't included. Sigh. Well, I have it now, thanks! – PearsonArtPhoto Jan 12 '16 at 2:13

It seems the problem is that I don't have a font specified, as determined by playing with the inspector text that came out. To do that, I simply needed to add the following text to my listed code.

nameText.font= Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.