I want to measure and return the time that passes between the time a user presses the Tab & the Space Button. Unfortunately my Code only returns 00:00:00. This is my code so far.
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 ();
}
}
}
You are re-creating the stopwatch when calling update. You can initialize the stopwatch on forehand in the "constructor".