I already solved it.
while (true) loop stops when panel is set to active
The increment of x stops if the second condition has been entered. Meaning the loop stops (right?)
IEnumerator CheckConnection (string url) {
while (true) {
yield return new WaitForSeconds (1);
x++;
WWWForm form = new WWWForm ();
WWW www = new WWW (url, form);
yield return www;
if (www.isDone && www.bytesDownloaded > 0) {
Debug.Log (x);
} else if (www.isDone && www.bytesDownloaded == 0) {
showLoginModal ();
loginModalText.text = "Please check your internet connection.";
closeButton.onClick.AddListener (hideLoginModal);
Debug.Log (x);
}
yield return null;
}
}
Hrm, are you asking us to test your code for you? You tell us if it stops or not! :D Some disagree with me but as far as I'm concerned, while you are anything less than Advanced at program$$anonymous$$g and Code dev NEVER use while(true). Ever. There are very very few cases where you can not use something else which would inevitably be safer than a non-ending loop. After all, given that its a Ticking Game Engine... the loops have already been made for you in the form of Update etc.
Always made sure to break
from a loop or at least to provide a break escape. return
from a function.
That said, if it works and isnt broken...win.
no. it really is stopping when the panel is set to active. i dont know why...
plus I can't StartCoroutine in Update() so I'm stuck in calling it at Start() and assigning an Update() - like loop in the IEnumerator
Nvm. I solved it. This is because the gameobject the script is attached to is being disabled when the panel is set to active. Thank you!