31 lines
785 B
C#
31 lines
785 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class AirChange : MonoBehaviour
|
|
{
|
|
|
|
// Update is called once per frame
|
|
void OnEnable()
|
|
{
|
|
StartCoroutine(ChangeAir());
|
|
|
|
}
|
|
|
|
private IEnumerator ChangeAir()
|
|
{
|
|
while (true) // 无限循环
|
|
{
|
|
string text = gameObject.GetComponent<Text>().text;
|
|
float air = float.Parse(text);
|
|
if (Random.Range(0, 10) < 2&&air>15)air=air-0.1f;
|
|
if (Random.Range(0, 10) >7&&air<35)air=air+0.1f;
|
|
gameObject.GetComponent<Text>().text = air.ToString();
|
|
int time = Random.Range(2, 5);
|
|
yield return new WaitForSeconds(time); // 等待两秒
|
|
}
|
|
|
|
}
|
|
}
|