Prevent expandable object from shrinking

I have a score board. It is relatively sized using the vertical layout group. The container keeps growing and shrinking though since the size of each digit is different.

ie: 2 is wider than 1.


Any suggestions?

I currently have two ideas but am having trouble editing the widths of objects…

  1. Set width of container/text if the characters change.

  2. Create a min-width script for the container and update it everytime the width increases.

Wait. I figured it out…

If anyone else needs a dynamic min-width, this script should work. :slight_smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class ScoreSizer : MonoBehaviour

    private RectTransform thatRect;
    private LayoutElement thatLayout;

    // Start is called before the first frame update
    void Start() {
        thatRect = gameObject.GetComponent<RectTransform>();
        thatLayout = gameObject.GetComponent<LayoutElement>();


    // Update is called once per frame
    void Update() {
        if (thatRect.rect.width > thatLayout.minWidth) {
            thatLayout.minWidth = thatRect.rect.width;