- Home /
How to clone ui buttons on ui panel from script?
I have UI Panel on my scene and UI Button as a prefab. Is it possible to populate this Panel with several instances of this button programmatically?
Yes. Since your UI buttons are game objects itself you can instantiate them like you do with your regular game object.
Yes. Since your UI buttons are game objects itself you can instantiate them like you do with your regular game object.
Oh! Thanks! But how in that case to add the function to a new instantiated ui button On Click event?
Answer by BrunoPaulino · Jan 10, 2015 at 08:51 PM
You can use the AddListener Function like that:
Button buttonToPress;
buttonToPress.onClick.AddListener ( () =>
Debug.Log("function added at run time.")
);
It uses the block concept. If you know Objective-C you probably had seen this.
Your answer
Follow this Question
Related Questions
What is the code to load a panel that is not a buildIndex scene? 1 Answer
finish button animation 0 Answers
In game right click menu 1 Answer
Enabling/Disabling a slider from script 0 Answers