Hi, this is a big problem so you need to decompose it in two small problems. The first one is to reset the timer, and the second is to make that occur during a reset.
For resetting the timer, you figured out yourself you need a method like so:
public void ResetTimer()
{
time = 0;
}
So, that one is solved, to fix the other small issue you need to know when a reset occurs. Is it when myCondition is false? If so then:
void Update(){
if (myCondition) {
GetComponent<Text> ().text = string.Format("{0:00}:{1:00}:{2:00}",Mathf.Floor(time/60),time%60,(time*100)%100);
time = (float)Time.time;
}
else {
ResetTimer();
}
}
If your reset occurs on a button clicked then you need to call ResetTimer() in the button event method.
Brathnann
no, my condition is not on time, but on a state of my games a bool that I will look for in another script.
dlorre my problem is not the condition method, your code works fine, my problem is that if I do a time = 0; , it does not reset my settings.
I don’t know how to write the code to reset a timer.
private float time;
public float Time
{
get { return time; }
set
{
time = value;
GetComponent<Text>().text = string.Format("{0:00}:{1:00}:{2:00}", 0, 0, 0);
}
}
that way when you set Time = 0 the display will be updated as well as the time variable.
dlorre yes i have translated the page.
I studied your code well, but I can’t integrate it.
I spend my float time privately.
but after the variable I don’t really understand:
{...}```
,
"Time" has neither a variable nor a void, and since my programming level is low, I'm having trouble understanding why it's structured like that.
I tried to copy this code without success.
[Kurt-Dekker](https://forum.unity.com/members/kurt-dekker.225647/)
thank you but I'm not sure that the resources you gave me are useful.
__What I'm trying to do is restart this :__

Oh come on, don’t name a local identifier the same as a UnityEngine class (Time)!
That’s just needlessly intentionally confusing.
Look at the problems you caused:
@venom789 just make a float for your timer, and DO NOT CALL IT Time because that is already in use by the system.
public float myTimer; // properly named timer
When you want it to count down for 7 seconds ,do this:
myTimer = 7.0f;
In Update():
if (myTimer > 0)
{
myTimer -= Time.deltaTime;
}
To find if it is “expired” or still counting down:
if (myTimer > 0)
{
Debug.Log( "timer is still running...");
}
else
{
Debug.Log( "timer is expired...");
}
That’s IT. If you want to display it all spiffy sharp like 00:00:00, go look at the C# time formatting documentation… all this stuff can be done by the .NET library without you writing crazy "{0:00}:{1:00}" kinds of nonsense.
Kurt Dekker
thank you but I’m not trying to make a count down , I’m creating a speed runner.
I created a watch, and I want it to reset to 0 when my level restarts.
@Kurt-Dekker ah good catch, I made this on the fly without thinking it was in use by Unity. The purpose of using a setter is to make sure that the object will update the display when the variable changes.