if keeps testing true when it shouldn't

I’m trying to script a timer and I’ve run into an issue I can’t explain yet.

void Update () {
		if (this.m_isCounting) {
			this.m_time = Time.time - this.m_frameTime + this.debugSeconds;
			if (this.m_time >= 60) {
				this.m_time -= 60;
				this.m_minutes += 1;
				Debug.Log ("Seconds if block");
			} 
			if (this.m_minutes / 60 == 1) {
				this.m_minutes -= 60;
				this.m_hours += 1;
				Debug.Log ("Minutes if block");
			} 

			this.m_counter.text = "" + this.m_hours + ":" + this.m_minutes + ":" + (int)this.m_time;
			//Debug.Log ("isCounting if block");
		}
}

What happens is my timer counts up nicely from 57 (the debugSeconds value) and m_time drops back to 0 because the first if block tests true. The problem is that this if block keeps testing true every frame after, which makes the hours tick like seconds while the minutes fly by (this project is making me feel old).

Initially I tried using == instead of >=, but there’s no difference either way. I’m not understanding why a test that should only return true when m_time is 60 keeps getting passed.

this.m_time is explicitly set in line 3. Adding or subtracting from it does not make any difference. It does not even need to be a member variable at all.

To keep your IF you would need to shift your start time by 60 seconds, but there are easier ways than to count up each frame until the correct number is reached.

I haven’t tested it, but something like this should do:

int secondsTillStart = (int)(Time.time - this.m_frameTime + this.debugSeconds);
int hours = secondsTillStart / (60 * 60);
int minutes = (secondsTillStart / 60) % 60;
int seconds = secondsTillStart % 60;