I have a coroutine function written for Unity which is as below:
IEnumerator initialize_reference_att()
{
Quaternion zero = new Quaternion(0, 0, 0, 0);
while (Input.gyro.attitude == zero)
Debug.Log("This line is required otherwise exits while without looping");
yield return null;
reference_attitude = Input.gyro.attitude;
Debug.Log("Reference attitude set to " + reference_attitude);
yield return null;
}
In this way it works as expected however when I write the while loop as below:
while (Input.gyro.attitude == zero)
yield return null;
the execution of while loop ends although Input.gyro.attitude == zero condition is still true. Apparently it has something to do with returning from coroutine immediately after while loop without doing any other thing. Because when I add an debug log line(as in the first code snippet), it works as expected. Does anybody have any idea why it behaves in that way? My issue is solved but I only want to understand why it happens. Thanks everyone.