我想测量并返回用户按下 Tab 和空格按钮之间经过的时间。不幸的是,我的代码只返回 00:00:00。到目前为止,这是我的代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
using System;
using System.Diagnostics;
using Debug=UnityEngine.Debug;
public class timer : MonoBehaviour {
public Stopwatch zeit;
void Update () {
zeit = new Stopwatch();
if (Input.GetKeyDown ("tab")) {
zeit.Start();
}
if (Input.GetKeyDown ("space")){
TimeSpan ts = zeit.Elapsed;
zeit.Stop ();
print(ts);
zeit.Reset ();
}
}
}?
Run Code Online (Sandbox Code Playgroud)