# Weird Problem with Clock

I am making a clock to work with my sun, and I have just lost my patients. I can not think of any reason why this script won’t work. What happens is that when the seconds hit 60, they set to 0 and stay there. Then the minutes start going up at light speed, resetting themselves the way they should, and then making the hours go up the way they should. I don’t have an idea what is going on, but I know that it aint right.

This is the basic clock system:

``````second = Time.time;

if(second >= 60)
{
second = 0;
minute ++;

if(minute >= 60)
{
minute = 0;
hour ++;

if(hour >= 24)
{
hour = 0;

}
}
}
``````

this isn’t a glitch, once the seconds are >= 60, you reset the variable second, witch is instantly changed back to Time.time when you call `second = Time.time;` you need to increment the seconds by one when 1 seconds passes, not directly set seconds like this: Replace second = Time.time; with

`

//c#

void Start ()
{
InvokeRepeating(“Increment”, 1, 1);
}

void Increment ()
{
second += 1;
}

Think about it…Time.time is a count in seconds since the game started, so when it gets to 60 and higher, your first if statement will always be true, so you will always set “second” to 0 and always increment “minute” by one and so on. When you reset “second” to 0, that has no effect on Time.time, which will continue counting up forever.

If you want to use this particular method, you should not use Time.time, but rather increment “second” by itself. I’d recommend using InvokeRepeating with an interval of 1.0, so you can have “second” be an integer that’s incremented by one every time the function is called. If you’re going to use Update, then make “second” a float where you add Time.deltaTime to it every frame. (But in that case, you’d want to do “`second -= 1.0`” instead of “`second = 0`”, in the interests of accuracy.)

This is because you are using Time.time. When what you want to use is Time.deltaTime (delta time is the change in time since the last update) you want to add that to your seconds (your missing a + before the = as well but that may just be a typo).

See Time.time stores the time since the app started. which once over a minute, will always be setting your second value to greater than 60 each update.