- Home /
More SelectionGrid Buttons? Or a better way to do this?
First off, apologies for the wall of text. I always feel I'm doing things wrong if I'm not being as detailed as possible.
Well, I'm pretty new here and just starting to get into GUI stuff. I'm an amateur at best when it comes to coding, but I would like to think I'm getting better. Anyway! I'm working on an inventory system/ship building system on one screen. Long story short, ship pieces all take one square worth of space and after hitting a finished button or what have you the ship is created in the 2D space of the actual game. I've got a large part of the game code finished, but now I've moved onto this and I'm a little stumped. Mostly because I've never worked with GUI before.
My initial plan was to have a selection grid that was 10x10. When a space is selected and you click on a button holding the materials in your inventory (Say, an iron block for example) that selection grid button changes to be an iron block image. Then I can simply construct the ship based on what texture is in each square. I'm honestly not -entirely- sure how to do that either, but that's a problem for another day, and I feel like I can figure it out at least. I hope.
Well, onto the real problem. I cannot for the life of me figure out how to make a selection grid have more than 4 buttons. I know it's stupid, but I just can't do it. The SelectionGrid accepts a variable it calls "xCount" which of course changes how many fit on each horizontal line, but there just doesn't seem to be something that controls how many buttons there are. Are you limited to 4? Or am I just the most unobservant person in the world? Also, if there is some glaringly obvious better solution to my current task than a selection grid, please do say so.
Thanks a lot for your time. It's amazing how helpful the people of this community are, and I wouldn't have had a chance even getting this far if it weren't for that.
Answer by Mike 3 · Oct 11, 2010 at 04:54 PM
It draws as many buttons as you pass strings in the texts parameters. Pass 16 strings, with an xCount of 4, and you'll end up with a 4x4 grid
Hmm... That's odd. $$anonymous$$y array of strings currently has 5 in it but I'm still getting 4 buttons. I modified the code example from the documentation and added a string, then played with the xCount variable and a few other things. I'll go take another look at it and make sure the fifth string is being passed properly, but... is there anything else?
That's weird. Now it's going up to 5, even though I added up to 8 strings. It didn't display 5 till I had 6 entered either. Quite baffled now haha.
Yet another quick update, it works whenever I close and reopen Unity. That is kinda odd. Problem solved-ish though. Thanks a lot!
Answer by Serellyn · Aug 20, 2012 at 08:18 PM
I know this is an old topic, but I noticed Kyouri saying that it won't reload until Unity restarts. The solution might be quite simple, if it's the same I had.
When you declare it as a public variable, Unity reminds the variables in his property inspector thingy. But change it to private and it will work like a charm.
So don't do this:
public string[] buttonStrings = new string[] {"Random Number", "Button 2"};
But do this:
private string[] buttonStrings = new string[] {"Random Number", "Button 2"};
Hope this helps for people that are struggling with this.
Your answer
Follow this Question
Related Questions
SelectionGrid is not returning a value!! 1 Answer
Remove Items and Item Tooltips 0 Answers
How To Make A Numeric Inventory System? 0 Answers
need to shorten my code but unsure of how 3 Answers
proper inventory system issue.. 1 Answer