Created
September 1, 2022 03:39
-
-
Save allfake/7d9a51362e3305fadd2bf48ee20bec52 to your computer and use it in GitHub Desktop.
UNITY auto size ui set max width
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Not work on Awake | |
private void Start() | |
{ | |
var rect = gameObject.GetComponent<RectTransform>(); | |
if (rect.rect.width > ScreenSizeHelper.MaxWidth) | |
{ | |
var height = rect.rect.height; | |
rect.anchorMin = new Vector2(0.5f, 0.5f); | |
rect.anchorMax = new Vector2(0.5f, 0.5f); | |
rect.sizeDelta = new Vector2(ScreenSizeHelper.MaxWidth, height); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment