- Home /
Created UI scales when screen stretched, but not on play?
I've created a debug panel for my game, where the buttons are generated dynamically to be easily added without needing to go into the panel prefabs.
If the screen starts small and is scaled up, everything works fine:
However, if I start the game in full screen, the created buttons are not scaled at all!
Here is my code for creating the buttons, what am I doing wrong?
int i=0;
//CommandButtons is just a dictionary with button name+color
foreach (var playerBut in CommandButtons){
//HudButton is the button object
Button but = GameObject.Instantiate(HudButton);
but.transform.SetParent(transform.Find("BG/Scroll View/Viewport/Commands"));
but.transform.Find("Text").GetComponent<TextMeshProUGUI>().text = playerBut.Key;
//Here!!! Why doesn't this scale??
RectTransform rect = but.GetComponent<RectTransform>();
rect.anchorMin = new Vector2(0, 1);
rect.anchorMax = new Vector2(1, 1);
rect.anchoredPosition = new Vector3(0, i * -30);
but.onClick.AddListener(delegate { ClickedCommandButton(playerBut.Key); });
i++;
}
Thanks!
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613045002im_/https://answers.unity.com/themes/thub/images/avi.jpg)