I’m trying to create a square in a mobile game by getting the width of the screen and setting the height to the width. For example:
VisualElement rootElement = GetComponent<UIDocument>().rootVisualElement;
VisualElement box = rootElement.Q<VisualElement>("Box");
box.style.height = Screen.safeArea.width;
However, when I do this, it makes the element too large (See attachment).
Anyone know how I can achieve this?
Check this previous post:
In your case, the both width and padding-top should be 100%
1 Like