Segment within a nested If does not get evaluated

I’m trying to do a multicounter script to keep track of time. So far, it just counts simulated seconds, minutes and hours using a coroutine and some nested if-else instructions. I’ve added an extra if-else structure within the minutes section to count degrees, assuming it will increment or decrement one degree per minute, yet this part of the code is as if it were invisible, for the compiler does not see it.

public class MultiCounter : MonoBehaviour {

	public bool process= true;
	public bool subprocess = true;
	public float timerSpeed = 0.125f;
	public int iSeconds, iMinutes, iHours;
	public int iDegrees = 0;

	// Use this for initialization
	void Start () {
		StartCoroutine (TripleCounter ());
	}
	
	IEnumerator TripleCounter()
	{
		while(process)
		{
			yield return new WaitForSeconds(timerSpeed);

			if(iSeconds >= 59)
			{
				iSeconds = 0;
				if(iMinutes >= 59)
				{
					iMinutes = 0;

					// Problematic code...
					if(iDegrees >= 359)
					{
						iDegrees = 0;
					}
					else
					{
						iDegrees++;
					}

					if(iHours >= 23)
					{
						iHours = 0;
					}
					else
					{
						iHours++;
					}
				}
				else
				{
					iMinutes++;
				}
			}
			else
			{
				iSeconds++;
			}

			Debug.Log(iHours + ":" + iMinutes + ":" + iSeconds + " " + iDegrees + "°");
		}
	}
}

Seconds, minutes and hours get incremented correctly, but nothing happens with degrees… Even a Debug.Log after the line iMinutes = 0; does not get evaluated, yet the rest of the code related to iHours does indeed evaluate correctly.

Any hep would be appreciated.

Thank you.

You’ve nested your iDegrees code inside your iMinutes code. That means that iDegrees will only be incremented as iMinutes rolls from 59 back to 0. To verify what I’m saying, add this to Start():

iMinutes = 59;

Then watch until iMinutes rolls over to 0. You will see iDegrees incremented. This may not be what you want, but this is what you wrote.

Why are you using:

yield return new WaitForSeconds(0.125f);// assuming timer speed actually stays at that value.

When you appear to be trying to count seconds and minutes? Why not just yield for 1 second each time?

As you have it, iSeconds++ will be called every 0.125 seconds, meaning it goes up by 8 for every second that actually passes. If this is what you want, then why not change the yield to 1 second and use iSeconds += 8 each time. Or you could keep using timerSpeed, but use it as an actual speed (iSeconds += timerSpeed), so timerSpeed == 2 means its going twice as fast as real time and == 8 means 8 times as fast.