I need help with creating three game objects as shown in the attached image:
The first object needs to stick to the left side of the screen.
The second object needs to stick to the right side of the screen.
The third object needs to stretch and fill all the space between the first and second objects.
This setup should be compatible with all mobile resolutions.
Thanks in advance.
DevDunk
February 26, 2024, 1:12pm
2
Use anchoring and percentages to controll how it scales.
This is easy with the canvas scaler
1 Like
DevDunk
February 26, 2024, 2:41pm
4
Google unity canvas scaler or how to make responsive UI
I am not going to do your work
Here are the official docs on how to make your UI handle various resolutions and aspect ratios cleanly:
Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:
It can be very fiddly but it is super-powerful once you reach comfort with the UI.
Building upon Praetor’s great post above, let me suggest this approach:
make a quick first draft of your UI.
in the Unity game window change the shape / dimensions of your Game window (you can even make your own resolutions)
see what happens to your UI in this new shape window
iterate and fix your anchors and scalings and whatnot
Make sure you do not overlook the Canvas Scaler settings. Personally I (almost) …
That seems excessive… What is the text of the actual complaint from them?
Make something like this with a fixed aspect ratio (in this case 2:1, maybe you need 3:1 or whatever suits your buttons), and ALL your buttons anchored inside it to never move within that box:
[7337383--891847--fixed_aspect_ratio_box.png]
then anchor that fixed against the bottom center (red dot below).
On the ipad it looks like:
[7337383--891850--ipad.png]
on the iPhone it looks like:
[7337383--891853--iphonex.pn…
Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings midway through, you will often need to redo your UI entirely.
I also use this CanvasScalerOrientationDriver
utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.
Familiarize yourself with: Auto Layout | Unity UI | 1.0.0
For your use case you just need a HorizontalLayoutGroup, and three children with LayoutElements with the correct settings.