- Home /
Is it possible to change the font/size/color of child text in a vertical layout group?
Hello! I am pretty new to Unity, and I haven't found an answer to this question anywhere yet. I am creating a 2D quiz game with a vertical layout group of buttons. The text in the buttons changes every question. The buttons are automatically created when the game is run as white rectangles with the text inside being Arial size 14. I want to change this, but I am not sure how since the buttons and their text settings only appear when the game is running. I have so far only been able to change them through those settings, but when the buttons are created again the settings don't stay. Thanks!!
what shows up in-game (plain white buttons, tiny Arial size 14 text)
what I'm looking for (different colored buttons, font and size of text changed)
Answer by xxmariofer · Jan 17, 2019 at 09:30 AM
Do you want to change the font / color and size every time you create the buttons? You can dynamicaly access those propertys like:
YOURBUTTONCREATED.GetChild(0).GetComponent<Text>().font = WHATEVERFONT;
YOURBUTTONCREATED.GetChild(0).GetComponent<Text>().fontSize = 3;
YOURBUTTONCREATED.GetChild(0).GetComponent<Text>().color= Color.red;
If you want your buttons to always have the same fontSize / color / and font just create a prefab in the editor with the values you deciden and get a reference to that prefab in the script with
public GameObject button;
and instantiate that button
Your answer
Follow this Question
Related Questions
Trouble with Unity2d Text 0 Answers
How to show score after enemy death.,How to show score after the death of the enemy. 1 Answer
RegisterDirtyLayoutCallback not working inside a vertical layout group 0 Answers
Programming 2D buttons 3 Answers
How to change the text of a button with a name from a list without the name repeating? 2 Answers