SetTextV.cs 794 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SetTextV : MonoBehaviour
  6. {
  7. public Text text;
  8. public Image bj;
  9. public RectTransform textRect;
  10. public RectTransform canvas;
  11. private Vector2 canvasSize;
  12. private void Start()
  13. {
  14. canvasSize = new Vector2(canvas.rect.width, canvas.rect.height);
  15. }
  16. public void SetText(string str)
  17. {
  18. if (str.Length > 100)
  19. text.fontSize = 20 - ((str.Length - 100) / 50 + 1) * 2;
  20. this.text.text = str;
  21. }
  22. public void SetBackGround (Sprite bj)
  23. {
  24. this.bj.sprite = bj;
  25. }
  26. private void FixedUpdate()
  27. {
  28. canvasSize.y = textRect.sizeDelta.y + 60;
  29. canvas.sizeDelta = canvasSize;
  30. }
  31. }