using UnityEngine; using System.Collections; using UnityEngine.UI; public class CheckTextStrLength : MonoBehaviour { public float with = 200; private Text mailText; RectTransform rect; RectTransform imgRect; void Start() { mailText = GetComponent(); rect = GetComponent(); } void Update() { float curWith = 0; mailText.text = mailText.text; if (mailText.preferredWidth < with) curWith = mailText.preferredWidth; else curWith = with; rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, curWith); rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, mailText.preferredHeight); } }