I'm quite new to Unity, so I'm sorry if this is a basic question. I've been trying to set up the UI for a mobile game, but I'm not quite sure how to make the UI lock it's position, no matter the screen size. I've tried using anchors (though I don't fully understand how to use them properly), I've tried using a canvas scaler, I've looked at the Unity document and I just can't seem to find an answer. The buttons are off screen/half off the screen when I build the game to my device/switch screen sizes in the game view. Does anyone know how to fix this?
Asked
Active
Viewed 1,004 times
-1
-
The problem is with your approach to the problem: "Lock its position no matter the screen size" is not doable, because screen sizes are different. It's the whole reason for the anchor system. What you need to do first is decide on your priorities. First, do you want them to take up the same _percentage_ of screen size? This sounds like what you probably want. Imagine two users with different screen sizes, one longer than the other. There's no way that your UI would look identical on both because the screens are not the same shape. Read through the anchor docs again with this in mind. – Joseph Dec 19 '20 at 23:06
1 Answers
0
You can set your anchor point by selecting the UI object (such as a button) and then clicking here and selecting the right anchor point. You can also press down shift to set the pivot and/or alt to move the object to that point at the same time. The object should now be anchored to that point and keep its position even if the resolution is changed. You can set a precise position from the inspector, too. Simply adjust the Pos X and Pos Y variables. It will still adhere to the anchor point.
Note that you might have to play around with the Canvas object's UI Scale mode and its settings to get the right setup.

Aweq
- 23
- 4