作者:卢-lydia09 | 来源:互联网 | 2023-10-10 15:56
游戏开始就开始记录时间:usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEn
游戏开始就开始记录时间:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;public class TimeCost : MonoBehaviour {private Text TimeTip;private float TimeCos;private float StartTime;private int TimeNum;private int m_Hour;//时private int m_Minute;//分private int m_Second;//秒private void Start(){TimeTip = transform.GetComponent();StartTime = Time.time;}// Update is called once per framevoid Update () {TimeCos = Time.time- StartTime;TimeNum = Mathf.FloorToInt(TimeCos);m_Hour =TimeNum / 3600;m_Minute = (TimeNum - m_Hour * 3600)/60;m_Second = TimeNum - m_Hour * 3600 - m_Minute * 60;TimeTip.text = "操作用时:" + m_Hour + "时" + m_Minute + "分" + m_Second+"秒";}private void OnEnable(){StartTime = Time.time;}
}