What the meaning of this code

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.

You have already posted this here . Please don’t double-post.

I have the same problem. I need help

Please don’t necro post, especially to posts with absolutely ZERO content in the first place.

Instead, make your own fresh post. When you post, keep this in mind:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
  • links to documentation you used to cross-check your work (CRITICAL!!!)

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

1 Like

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

I love how this thread is basically:

  • A duplicate posting OP
  • Someone asking not to duplicate post
  • Someone necro posting
  • Someone asking not to neco post
  • Someone demonstrating they didnt read any of the above before posting

Ill continue the chain by asking to read the actual thread before posting i guess :smile::stuck_out_tongue:

2 Likes

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.