首页 > 代码库 > 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#获取游戏时间并显示成秒表格式