- Home /
Unity 4.6 GUI at runtime!
Hi! How can i add the new GUI at runtime? I need something like the old GUI system at OnGUI() method (GUI.Button(new Rect(10, 10, 10, 10), "Button");) How can i do that?
You could probably instantiate button prefabs or generate the buttons at run-time. I just don't understand why you wouldn't want to use the new system's designer (it's really nice).
Because, for example if i want to make a list of buttons and I dont know exactly how many buttons will be in that list, i cannot make the buttons from the designer. $$anonymous$$ore specific example, in an mmorpg you have characters. If i want to make a button for each character i cannot do it from designer, first i need to get the character's properties (and the count) from the server and just after that i am able to make the buttons! Thanks for the tip!
Answer by AyAMrau · Aug 27, 2014 at 04:34 PM
All new GUI elements are components so you will need to instantiate game objects and either add those components or premake prefabs and instantiate those.
But it's probably more efficient to make entire screens or sections that you will instantiate instead of separate elements.
Your answer
![](https://koobas.hobune.stream/wayback/20220613161642im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Canvases, paste/skin them to other objects in a single scene 0 Answers
Referencing a variable in another script possibly not working? 0 Answers
Dynamically populate variable number of sprites on grid layout group 0 Answers
Specify background color of Gui.Button at runtime 1 Answer
How to set a texture resource to texture type "GUI" by script? 1 Answer