unity 计算时间的插差值

 

Stopwatch

实例可以测量一个时间间隔的运行时间,也可以测量多个时间间隔的总运行时间。调用Start方法时,开始累积运行时间计数;调用Stop方法时,结束当前时间间隔测量,并冻结累积运行时间值;调用Reset方法可以清除现有实例中的累积运行时间。通过属性ElapsedElapsedMillisecondsElapsedTicks查询运行时间值。

 

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;

public class Shijian_chazhi : MonoBehaviour {
	Stopwatch stopwatch = new Stopwatch ();

	// Use this for initialization
	void Start () {

		stopwatch.Start ();
//		for (int i = 1; i < 1000000; i++) {
//		
//		}

	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown ("o")) {
//			stopwatch.Stop ();
			UnityEngine.Debug.Log ("stopwatch" + stopwatch.Elapsed);
		}

	}
}

 

 

 

 

 

上的定义  需要开始计时的   就写的上stopwatch.Start ();   是打开计算时间的函数方法  当都需要关闭之时stopwatch.Stop (); 调取这个即可  就会停止计时 这个输出的时间格式是 00:00:00  的格式  时/分/秒

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值