NG_/Assets/Scripts/UI/事态感知/XieLouJianCe.cs

32 lines
775 B
C#
Raw 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 XieLouJianCe : MonoBehaviour
{
public Text text;
public Image image;
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 > 5) air--;
if (Random.Range(0, 10) >6&&air<80)air++;
text.text = air.ToString();
image.fillAmount = (float)air / 100;
int time = Random.Range(1, 3);
yield return new WaitForSeconds(time); // 等待两秒
}
}
}