You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class WeatherInfo : MonoBehaviour
|
|
{
|
|
public Text temperature;//温度19-21
|
|
public Text windSpeed;//风速 5.8-7.1 m/s
|
|
public Text airPressure;//气压 100.5-101.5 kpa
|
|
public Text pm2_5;// 85ug/m3
|
|
public Text humidity;//湿度 31.5-32.7 %
|
|
public Text windDir;
|
|
public Text noise;// 31.5 - 40db
|
|
public Text pm10;// 50-55 ug/m3
|
|
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
|
|
StartRandomChangeValue(temperature, 0.1f, 3, 8);
|
|
StartRandomChangeValue(windSpeed, 0.1f, 10, 20);
|
|
StartRandomChangeValue(airPressure, 0.2f, 15, 20);
|
|
StartRandomChangeValue(pm2_5, 1f, 5, 20);
|
|
StartRandomChangeValue(humidity, 0.3f, 5, 20);
|
|
StartRandomChangeValue(noise, 0.5f, 2, 10);
|
|
StartRandomChangeValue(pm10, 1f, 4, 20);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartRandomChangeValue(Text txt, float rangeValue, float minTime, float maxTime)
|
|
{
|
|
StartCoroutine(RandomChangeValue(txt,rangeValue,minTime,maxTime));
|
|
}
|
|
|
|
|
|
IEnumerator RandomChangeValue(Text txt, float rangeValue,float minTime,float maxTime)
|
|
{
|
|
float time = Random.Range(minTime, maxTime);
|
|
yield return new WaitForSeconds(time);
|
|
float range = Random.Range(-rangeValue, rangeValue);
|
|
float value = float.Parse(txt.text)+range;
|
|
|
|
txt.text = value.ToString("0.0");
|
|
//循环携程
|
|
StartCoroutine(RandomChangeValue(txt, rangeValue, minTime, maxTime));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|