40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
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<TextMeshProUGUI>().text;
|
|
string fontText1 = numberText.GetComponent<TextMeshProUGUI>().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<TextMeshProUGUI>().text = number.ToString()+unit;
|
|
numberText.GetComponent<TextMeshProUGUI>().text = number1.ToString()+unit;
|
|
int time = Random.Range(2, 5);
|
|
yield return new WaitForSeconds(time); // 等待两秒
|
|
}
|
|
|
|
}
|
|
}
|