首页 > 代码库 > Unity3D中C#获取游戏时间并显示成秒表格式
Unity3D中C#获取游戏时间并显示成秒表格式
using UnityEngine;using System.Collections;public class time1 : MonoBehaviour { float time = 0; int minutes,seconds,microseconds; //public GameObject lab; // Use this for initialization void Start () { //lab = this.lab ; } // Update is called once per frame void Update () { time += Time.deltaTime; minutes = ((int)time)/60; seconds = ((int)time)-(((int)time)/60)*60; microseconds = (int)(time*100)- (int)(time*100)/100*100; if( minutes == 0 ) { if(seconds == 0) { if(microseconds == 0) { Debug.Log("00:00:00"); } if(microseconds>0 && microseconds< 10) { Debug.Log("00:00:0" + microseconds); } if(microseconds>9) { Debug.Log("00:00:" + microseconds); } } if(seconds > 0 && seconds < 10) { if(microseconds == 0) { Debug.Log("00:0"+ seconds+":00"); } if(microseconds > 0 && microseconds < 10) { Debug.Log("00:0"+ seconds+":0"+microseconds); } if(microseconds >9) { Debug.Log("00:0"+ seconds+":"+microseconds); } } if(seconds > 9 && seconds < 60) { if(microseconds==0) { Debug.Log("00:"+seconds+":00"); } if(microseconds > 0 && microseconds < 10) { Debug.Log("00:"+ seconds+":0"+microseconds); } if(microseconds > 9) { Debug.Log("00:"+ seconds+":"+microseconds); } } } if(minutes > 0&& minutes <10) { if(seconds == 0) { if(microseconds == 0) { Debug.Log("0"+minutes+ ":00:00"); } if(microseconds>0 && microseconds< 10) { Debug.Log("0"+ minutes +":00:0" + microseconds); } if(microseconds > 9) { Debug.Log("0"+minutes+ ":00:"+microseconds); } } if(seconds > 0 && seconds < 10) { if(microseconds == 0) { Debug.Log("0"+minutes+":0"+ seconds+":00"); } if(microseconds > 0 && microseconds < 10) { Debug.Log("0"+minutes+":0"+ seconds+":0"+microseconds); } if(microseconds > 9) { Debug.Log("0"+minutes+":0"+ seconds+":"+microseconds); } } if(seconds > 9 && seconds < 60) { if(microseconds == 0) { Debug.Log("0"+minutes+":"+seconds+":00"); } if(microseconds>0 && microseconds< 10) { Debug.Log("0"+minutes+":"+seconds+":0"+microseconds); } if( microseconds > 9) { Debug.Log("0"+minutes+":"+seconds+":"+microseconds); } } } if(minutes>9) { if(seconds == 0) { if(microseconds == 0) { Debug.Log(minutes+ ":00:00"); } if(microseconds>0 && microseconds< 10) { Debug.Log(minutes +":00:0" + microseconds); } if(microseconds > 9) { Debug.Log(minutes+ ":00:"+microseconds); } } if(seconds > 0 && seconds < 10) { if(microseconds == 0) { Debug.Log(minutes+":0"+ seconds+":00"); } if(microseconds > 0 && microseconds < 10) { Debug.Log(minutes+":0"+ seconds+":0"+microseconds); } if(microseconds > 9) { Debug.Log(minutes+":0"+ seconds+":"+microseconds); } } if(seconds > 9 && seconds < 60) { if(microseconds == 0) { Debug.Log(minutes+":"+seconds+":00"); } if(microseconds>0 && microseconds< 10) { Debug.Log(minutes+":"+seconds+":0"+microseconds); } if( microseconds > 9) { Debug.Log(minutes+":"+seconds+":"+microseconds); } } } } }
Unity3D中C#获取游戏时间并显示成秒表格式
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。