projectEli/Assets/Inventory System/Scripts/Helpers/DeriveSizeFromChild.cs
2023-03-16 15:44:34 -07:00

35 lines
978 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeriveSizeFromChild : MonoBehaviour
{
RectTransform rect;
RectTransform childRect;
public float MinimumSize;
public float MinimumSizeX;
// Start is called before the first frame update
void Start()
{
rect = GetComponent<RectTransform>();
}
// Update is called once per frame
void Update()
{
if(childRect == null && transform.childCount > 0 && transform.GetChild(0) != null)
{
childRect = transform.GetChild(0).GetComponent<RectTransform>();
}
if (childRect != null && rect != null)
{
//Debug.Log(childRect.rect);
if(childRect.rect.height > MinimumSize)
rect.sizeDelta = new Vector3(rect.sizeDelta.x, childRect.sizeDelta.y);
else
rect.sizeDelta = new Vector3(rect.sizeDelta.x, MinimumSize);
}
}
}