How to show different content in panel depending on which button was clicked to open the panel

Hi all,

I am a newbie to Unity with just some basic knowledge in programing.
Working currently on a school project, were I would need some help.

Well, I have several buttons in my scene - all for another purpose (“Add label” to GameObject, “Delete label” from GameObject and “View labels” of the GameObject).
If a button is clicked a panel will open with a text, inputfield and buttons in it.
I would like to use only one panel but depending on which button was clicked to open the panel, different content - meaning different text, inputfield and buttons shall be displayed.

Is there any way to achieve this?

Would be really thankful, if someone could help… :slight_smile:

Yes, it’s very much achievable.

However, making different panels seems like it would be much easier, is there a reason why you want to do it the other way?

one of another student mentioned last time that its better to use only one panel due to performance issues etc.

Could you kindly describe how i can achieve that?

You would have a few prefabs for the Text, InputField, and Buttons that you’d want to have on your panel, and then when the button is clicked, you make a copy of them and place them on (probably with some sort of GridLayoutGroup to automatically align them). Then you’d have to manually hook up each field or button to a method you want it to call, which is the part that would be annoying.

If you have less than 100 panels, I’d say there’s a pretty low chance of performance issues, unless you’re doing something wrong. You could probably even realistically have way more with no issue. You shouldn’t really worry about performance unless something’s obviously going to be a problem, what you’re suggesting seems like a minor improvement with next to no increase in performance.

Mhh sounds like time-consuming and annoying than creating 3 panels for each button. I think I will go then for the latter one… :-/