Hey all,
I’m having no luck with this question in Unity Answers, so maybe the forum is a more appropriate place for it, and maybe expand on what I’m asking.
I’ve been recently making GUI elements change according to screen size using something like the following:
hudWindowRect = Rect((hudWindowRectX / 100) * Screen.width, (hudWindowRectY / 100) * Screen.height, (hudWindowRectW / 100) * Screen.width, (hudWindowRectH / 100) * Screen.height);
This is working for me fine. Each element in the Rect has its own variable worked as a percentage, so I can move elements around while in play mode until they’re where I want them, I then copy the component and paste in the values outside of play mode. And because they’re percentages, it adjusts to screen size.
But I have two problems. The main one is working out to to do this in arrays. I’m working on a shop at the moment and I’ve made a pretty extensive inventory for a different project and they both use arrays of rects for button and label elements. So I can’t (or don’t know how) to get into each individual one to resize it according to screen size.
Example of my code:
var index=0;
for(var a in shipsToBuy){
if(GUI.Button(shipsToBuyPosition[index],shipsToBuy[index].shipIcon, "ShipButtonStyle")){
}
Secondly, things are getting unwieldy already, with a lot of variables (4 for each element). So if I could work this method into arrays, I can see it becoming almost unworkable. Rects are nice and handy in the inspector the way you can show and hide them, but my method means each one must have 4 separate variables, so after 5 or 6 elements, it’s very easy to get lost.
So, main question is, is there a more elegant solution for this? I’ve seen a lot of answers to the broad question of resizing, but can’t find anything related to arrays of rects, or much that doesn’t just say ‘work it out as a percentage’.
I’m coding in Javascript, suppose my level could be described as an intermediate beginner. Any help or even discussion would be appreciated.