using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SetTextV : MonoBehaviour { public Text text; public Image bj; public RectTransform textRect; public RectTransform canvas; private Vector2 canvasSize; private void Start() { canvasSize = new Vector2(canvas.rect.width, canvas.rect.height); } public void SetText(string str) { if (str.Length > 100) text.fontSize = 20 - ((str.Length - 100) / 50 + 1) * 2; this.text.text = str; } public void SetBackGround (Sprite bj) { this.bj.sprite = bj; } private void FixedUpdate() { canvasSize.y = textRect.sizeDelta.y + 60; canvas.sizeDelta = canvasSize; } }