小编Fre*_*red的帖子

我在 Unity 中使用了 C# 秒表类,但它只返回 00:00:00

我想测量并返回用户按下 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)

.net c# stopwatch unity-game-engine

2
推荐指数
1
解决办法
9285
查看次数

标签 统计

.net ×1

c# ×1

stopwatch ×1

unity-game-engine ×1