H_SafeExperienceDrivingSystem/U3D_DrivingSystem/Assets/Script/Old/CurrentTime.cs

75 lines
2.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CurrentTime : MonoBehaviour
{
private float Max_Battery = 100f;//最大电量
private float Min_Battery = 0f;//最大电量
public static float Current_Battery = 35f;//最大电量//30
public float consumption=1f;//消耗电量速度
public Text txt_battery;
public Text txt_battery2;
//电量低提示UI
public GameObject obj2;
//private float timespeed=0;
// Start is called before the first frame update
int hour;
int minute;
int second;
int millisecond;
// 已经花费的时间
float timeSpend = 0.0f;
// 显示时间区域的文本
public Text text_timeSpend;
void Start()
{
// text_timeSpend = GetComponent<Text>();
obj2.SetActive(false);
}
void Update()
{
timeSpend += Time.deltaTime;
hour = (int)timeSpend / 3600;
minute = ((int)timeSpend - hour * 3600) / 60;
second = (int)timeSpend - hour * 3600 - minute * 60;
millisecond = (int)((timeSpend - (int)timeSpend) * 1000);
text_timeSpend.text = string.Format("{0:D2}:{1:D2}:{2:D2}", hour, minute, second);
//.{1:D2}, millisecond
if (Trigger_road.dian)
{
if (Current_Battery < 99)
Current_Battery += consumption * Time.deltaTime*2.5f;
txt_battery.text = Current_Battery.ToString("f0") + "%";
txt_battery2.text = Current_Battery.ToString("f0") + "%";
if (Current_Battery > 15.4F) obj2.SetActive(false);
}
else
{
if (Current_Battery > 1)
{
Current_Battery -= consumption*Time.deltaTime;
txt_battery.text = Current_Battery.ToString("f0") + "%";
txt_battery2.text = Current_Battery.ToString("f0") + "%";
}
if (Current_Battery < 15.4F)
{
obj2.SetActive(true);
}
else
{
obj2.SetActive(false);
}
//if (Current_Battery > 95)
//{
// Current_Battery = 95;
//}
}
}
}