- Home /
store many GameObjects
I have a game with a lot of buttons and if for each of them there is a specific pack of other buttons and so on. To use the buttons i made arrays which i filled in the inspector. But for the third page of buttons, i would need about 16 arrays so far and i'm planning to add even more buttons in the futuzre. I also can't use multi dimensional arrys because they don't show up in the inspector. Does anyone have an idea how to store the buttons without using one massive array or a lot of small ones?
sorry, i'm just a beginner in c# and unity. what exactly do you mean by that? my issue is that with the many individual arrays i can't use a for loop that goes through all the buttons and a large array would be extremely cluttered.
Answer by keroltarr · Feb 28 at 09:46 PM
It sounds like you are doing a bunch of nesting.
You could use the hierarchy for this.
Each button would have a number of child buttons that would be disabled by default.
Whenever a button is clicked a script could then enable all its children.
To navigate you could loop through all a buttons children.
So, i wouldn't need to make arrays for the GameObjects and could just acces the buttons inside the other buttons?
Yes it just depends on how you structure it. If you name your buttons in a particular way you can use Find() to find them by name and from a parent button to get its children. In a script you can use FindObjectsOfType()to find all the buttons and return an array.
How exactly would this look like? Find(ParenObject ChildObjectName ) ?
Answer by xxmariofer · Feb 28 at 09:17 PM
What's the exact issue you are having with the array? That you need to fill manually in the inspector? I would probably go with one script with one array attached to the parent and for each parent have all the child's buttons in the parent array, and that script recursively
Your answer
Follow this Question
Related Questions
looking for a way to set an integer to another number based on a condition. 2 Answers
Attacking mulitple targets simultanously 2 Answers
How to return control back to the original script? 1 Answer
Trying to find the highest number than add it to itself. 2 Answers
Having trouble using SendMessage 1 Answer