- Home /
How to deal with many buttons in the Inspector
I have many Buttons in my new project but i dont know how to get them so, that i dont have to connect any button to any game object. For example i have 50 levels and 50 butons for them. Because of that i need to connect my 50 buttons in the Inspector to Level 1, i need to connect my 50 buttons in the Inspector to Level 2 and so on. Does somebody know how to code, that i only need to connect the Level 1 button to the Level 1 game object without doing 50 scripts? I tried it with [SerializeField] but theres no difference. I hope i described it not to bad, im from Germany.
Thanks:)
Answer by lvskiprof · Jul 15, 2021 at 10:41 PM
If I understand your description it sounds like you need a singleton script that handles all 50 buttons and exists for all levels. Take a look here for how to use a Singleton: https://answers.unity.com/questions/891380/unity-c-singleton.html
That way you only need a single script and each level would be using the same script to manage the buttons. You can put the buttons together in a Prefab configuration that you simply have present on all your levels.
I hope that helps.
Your answer
Follow this Question
Related Questions
[c#] first script isnt disabling canvas and player cant move (issue with first script) 0 Answers
How do I get a 3D object visible in Canvas whilst keeping Screen Space-Overlay 0 Answers
[c#] first script isnt disabling canvas and player cant move (issue with first script) 1 Answer
Check UI panel touched after OnEnable()? 0 Answers
How to get PointerEventDatas[]? 0 Answers