- Home /
Easier way to resize group of buttons to the same size
I have a canvas with buttons, with a script attached to each button. This script creates an array for buttons and resizes every button to the same size as the longest one in that array (the button with the longest line of text in it). Everything works, but I was wondering: is there is an easier, more automatic way for this instead of having to drag every button in every array in the Inspector tab?
Any ideas would be greatly appreciated
UnityPackage: https://transfer.sh/6BCDG/buttonwidth.unitypackage
public Image[] otherbutton;
void Start () {
for (int i = 0; i < otherbutton.Length; i++)
{
if (otherbutton[i].rectTransform.sizeDelta.x > gameObject.GetComponent<Image>().rectTransform.sizeDelta.x)
{
gameObject.GetComponent<ContentSizeFitter>().enabled = false;
gameObject.GetComponent<Image>().rectTransform.sizeDelta = new Vector2(otherbutton[i].rectTransform.sizeDelta.x, otherbutton[i].rectTransform.sizeDelta.y);
}
}
}
Comment