using UnityEngine; using UnityEngine.UI; public class NewMonoBehaviourScript : MonoBehaviour { private GridLayoutGroup _gridLayoutGroup; private RectTransform _rectTransform; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start() { _gridLayoutGroup = GetComponent(); _rectTransform = GetComponent(); } // Update is called once per frame void Update() { var max = (_rectTransform.rect.width / (_gridLayoutGroup.cellSize.x+_gridLayoutGroup.spacing.x)) * (_rectTransform.rect.height / _gridLayoutGroup.cellSize.y+_gridLayoutGroup.spacing.y); var current = transform.childCount; if (current / max >= 0.8f) { _gridLayoutGroup.cellSize = new Vector2(_gridLayoutGroup.cellSize.x * 0.9f, _gridLayoutGroup.cellSize.y * 0.9f); } } }