using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TimeGame : MonoBehaviour
{
private float roundStartTime;
private int waitTime;
// Start is called before the first frame update
void Start()
{
Debug.Log("Press the Space Bar once you think the allotted time is up.");
SetRandomNumber();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
float playerWaitTime = Time.time - roundStartTime;
float error = Mathf.Abs(waitTime - playerWaitTime);
Debug.Log("You waited for " + playerWaitTime + " Seconds. That is " + error + " Seconds off.");
SetRandomNumber();
}
}
private void SetRandomNumber()
{
roundStartTime = Time.time;
Debug.Log(roundStartTime);
waitTime = Random.Range(5, 21);
Debug.Log(waitTime + " Seconds.");
}
}//Class
This is my Code, I am new to unity and c# Scripting, In this case I watch Sebastian Lague video and crete this one, the problem is, That i didn’t know how to get playerWaitTime, how to get playerWaitTime like that. It means roundStartTime = Time.time and how to get player waut Time by Time.time - roundstart Time(Time.time)(i think Time.time - Time.time = 0), how to get that, pls sorry for my bad english, and i didn’t know how to tell.
Time.time -Time.time is not equal to 0 Time.time gets the time that passed . For example if you use Time.time at 30 seconds you get 30 if you use it at 50 seconds it gets 50
I don’t think anyone can help post is not clear. What I understand is lets say round started at 00:20 and time is 00:30 if you substract round time from Time.time you get waiting time
With Forums you have to train yourself to read the dates. This Q is 2 years old. It popped back up because someone added one useless new thing to it, and the system’s front page reports that as the date. You have to train yourself to read the date on the bottom of the first post.
Of course it’s fine to reply to old stuff if it’s still relevant. But I’m pretty sure no one today has this particular confusion about Sebastian’s code.