New to unity. Please help…
I want to make it so when i press space it resets Time.time to 0.
You can’t change Time.time, since it is read-only: Unity - Scripting API: Time.time
However you can use Time.timeSinceLevelLoad instead: Unity - Scripting API: Time.timeSinceLevelLoad
That will give you the time since you last loaded a scene, as you are doing when the user hits the spacebar. By the way, just some extra advice: Application.LoadLevel is obsolete. You should use SceneManager.LoadScene instead.
If you want more fine-grained control, you can simply create your own variable (a float), save the current Time.time value to it when an event you care about happens, then compare Time.time to the time you saved to figure out how much time has passed since that event.
Everything that @PraetorBlue said above is spot-on, plus for that custom time variable, you can just increment it yourself too:
float time; // class variable
void Update()
{
time += Time.deltaTime;
}
Well i got it working like this:
Round down to int:
I’m sure there’s also an overload to float.ToString() that can discard decimals, don’t know it by heart.
Also, please look at the sticky post about code tags rather than posting your code as screendumps.