NG_/Assets/Scripts/UI/室内信息/DataZengJian.cs

38 lines
926 B
C#
Raw Normal View History

2024-12-13 19:40:05 +08:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class DataZengJian : MonoBehaviour
{
public float max;
public float min;
public float value;
void OnEnable()
{
StartCoroutine(insertText());
}
private IEnumerator insertText()
{
while (true)
{
string fontText = gameObject.GetComponent<TextMeshProUGUI>().text;
float number = float.Parse(fontText);
if (Random.Range(0, 10) > 7&&number<max)
{
number+=value;
}
if (Random.Range(0, 10) > 7&&number>min)
{
number-=value;
}
gameObject.GetComponent<TextMeshProUGUI>().text = number.ToString();
int time = Random.Range(2, 5);
yield return new WaitForSeconds(time); // 等待两秒
}
}
}