NG_/Assets/Scripts/UI/综合信息/HaoCaiGuanLi.cs

32 lines
824 B
C#
Raw Permalink Normal View History

2024-12-13 19:40:05 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HaoCaiGuanLi : MonoBehaviour
{
public Text text;
public Image image;// Start is called before the first frame update
void OnEnable()
{
StartCoroutine(ChangeAir());
}
private IEnumerator ChangeAir()
{
while (true) // 无限循环
{
string text1 = text.text;
int air = int.Parse(text1);
if (Random.Range(0, 10) < 3&&air > 0) air--;
if (Random.Range(0, 10) >6&&air<300)air++;
text.text = air.ToString();
image.fillAmount = (float)air / 300;
int time = Random.Range(1, 3);
yield return new WaitForSeconds(time); // 等待两秒
}
}
}