Basically I'm pulling data off a database and displaying said information if you click on buttons. However there is an infinite number of objects that are stored inside this database. I know how to position objects in a GUI if there are a finite number of them, but how would I achieve something like this with an infinite number of them? How could I set the X and Y positions for each new button?
There was quite a simple solution to this one, just using a for loop, and incrementing the X and Y dimension variables. I thought it would effect all the buttons in the loop, but I was wrong.
Scrollview as SpikeX said, but if there is really a LOT of them, it may be too many for one list. Can you structure the number of objects to choose from with some criteria to shorten the list? For example 'Starting with the letter A' or 'the shortest ones' or some other way of dividing up the list? Thus you might have 2 or more UI objects (say, one scrollview for 'narrow the search' and another for 'pick from those found').
Data visualization is a big field of study, worth googling. I've found that making hierarchies (trees, for example) that hide/show their children works pretty well. Then you can make them 'share the screen' by not all being on screen at the same time.
I think I know what you want, and the answer is to use maths to set the coordinates of the button instead of hard and fast values. a "for" loop with incrementing numbers is our chosen method, as long as the list doesn't get too big, the code below takes an array of string choices called pchoices (set elsewhere) and builds buttons on incrementing coordinates. I use the "vButChosen" Variable to execute the button action in an update.
int vMakeRoom=20;
int vButHeight=Screen.height/15;
int vButWidth=(int)(vButHeight*6.1f);
int vButPadding = vButHeight/5;
int vButPlaceX=Screen.width-vButWidth-vButPadding;
int vButPlaceY=Screen.height-(pChoices.Length*(vButHeight+vButPadding));
Rect vLoc;
vButChosen="Null";
for (int vBut=0;vBut<pChoices.Length;vBut++){
vLoc=new Rect(vButPlaceX,vButPlaceY+vBut*(vButHeight+vButPadding),vButWidth,vButHeight);
if(GUI.Button(vLoc,pChoices[vBut])){
vButChosen=pChoices[vBut];
}
}
}
I know that this is a bit long winded, but does it help?
Cheers,
James