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.