38 lines
926 B
C#
38 lines
926 B
C#
|
|
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); // 等待两秒
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|