using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class InsertInt : MonoBehaviour { // 引用TextMeshPro组件 public TextMeshProUGUI numberText; public string unit = "m"; // 设置单位 void OnEnable() { StartCoroutine(insertText()); } private IEnumerator insertText() { while (true) { string fontText = gameObject.GetComponent().text; string fontText1 = numberText.GetComponent().text; fontText = fontText.Split(' ')[0]; fontText1 = fontText1.Split(' ')[0]; int number = int.Parse(fontText); int number1 = int.Parse(fontText1); if (Random.Range(0, 10) > 7) { number++; number1++; } gameObject.GetComponent().text = number.ToString()+unit; numberText.GetComponent().text = number1.ToString()+unit; int time = Random.Range(2, 5); yield return new WaitForSeconds(time); // 等待两秒 } } }