20 lines
471 B
C#
20 lines
471 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AutoResize : MonoBehaviour
|
|
{
|
|
public RectTransform parentRect; // 父物体的 RectTransform
|
|
public Text taskText; // Text 组件
|
|
|
|
void Update()
|
|
{
|
|
//获取文本的预期高度
|
|
float textHeight = taskText.preferredHeight;
|
|
|
|
//更新父物体的高度
|
|
parentRect.sizeDelta = new Vector2(parentRect.sizeDelta.x, textHeight);
|
|
}
|
|
}
|