首页 > 编程语言 > 详细

Unity3D中C#获取游戏时间并显示成秒表格式

时间:2015-07-13 10:18:12      阅读:285      评论:0      收藏:0      [点我收藏+]
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Timer : MonoBehaviour {

    int hour;
    int minute;
    int second;
    int millisecond;

    // 已经花费的时间
    float timeSpend = 0.0f;

    // 显示时间区域的文本
    Text text_timeSpend;

	// Use this for initialization
	void Start () {
        text_timeSpend = GetComponent<Text>();
	}
	
	// Update is called once per frame
	void Update () {
        timeSpend += Time.deltaTime;
        GlobalSetting.timeSpent = timeSpend;

        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}.{3:D3}", hour, minute, second, millisecond);
	}
}



    
        

版权声明:本文为博主原创文章,未经博主允许不得转载。

Unity3D中C#获取游戏时间并显示成秒表格式

原文:http://blog.csdn.net/ixiaochouyu/article/details/46858545

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!