- Home /
Resizing elements to screen size within Array
Hey all. I've a variation on the frequent resizing GUI elements according to screen size question. I can't find the answer to this one.
At the moment I'm using this:
hudWindowRect = Rect((hudWindowRectX / 100) * Screen.width, (hudWindowRectY / 100) * Screen.height, (hudWindowRectW / 100) * Screen.width, (hudWindowRectH / 100) * Screen.height);
This works fine for individual Rects; I've the Rect object itself set to private and then I have the 4 float variables (X, Y, Width, Height) so I can get the positioning correct through the inspector while running the game. And everything resizes perfectly if I change resolution.
I'm now creating a rect array, so I can have a selection of buttons in it, which then in turn point to different scripts that I pull info from. How would I go about getting each one of those to resize?
var index=0;
for(var a in shipsToBuy){
if(GUI.Button(shipsToBuyPosition[index],shipsToBuy[index].shipIcon, "ShipButtonStyle")){
}
The above is just a small snippet. Everything is working apart from the resizing and position of the buttons according to screen size. shipsToBuyPosition[] is the Rect array here.
Any ideas?
Your answer
![](https://koobas.hobune.stream/wayback/20220613115124im_/https://answers.unity.com/themes/thub/images/avi.jpg)