NG_/预制体/渲染后整体打包/RandomNumberInt.cs

31 lines
852 B
C#
Raw Normal View History

2024-12-13 18:49:44 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using Random = UnityEngine.Random;
public class RandomNumberInt : MonoBehaviour
{
// Start is called before the first frame update
void OnEnable()
{
StartCoroutine(random());
}
private IEnumerator random()
{
while (true) // 无限循环
{
string fontText = gameObject.GetComponent<TextMeshProUGUI>().text;
int number = int.Parse(fontText);
if (Random.Range(0, 10) < 2&&number>0)number--;
if (Random.Range(0, 10) >7&&number<1000)number++;
gameObject.GetComponent<TextMeshProUGUI>().text = number.ToString();
int time = Random.Range(2, 5);
yield return new WaitForSeconds(time); // 等待两秒
}
}
}