This script works fine using UI “Buttons”
However, I am looking to use GetKeyDown & GetKeyUp functions to start and stop the timer.
It seems logical to do but I just can’t find a solution using Input.GetKeyDown functions.
float val;
bool timerActive;
public Text timerText;
// Start is called before the first frame update
void Start()
{
val = 0;
timerActive = false;
}
void Update()
{
if (timerActive)
{
val += Time.deltaTime;
}
double b = System.Math.Round(val, 2);
timerText.text = b.ToString("F2");
}
public void startbutton()
{
timerActive = true;
}
public void stopbutton()
{
timerActive = false;
}