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); // 等待两秒 } } }