Hi all,
My game requires an internet connection, so I have a class that at regular intervals, uses the WWW class to request a page from my website. If there’s no error returned then the game has a connection, else there was a problem and there’s no connection - an event is triggered for both outcomes, and the UI changes to prompt the user that they need an internet connection to continue using the game.
In the editor this works great and is very responsive. On mobile though, none of the events are firing.
Attached is a screenshot from the mobile dev version. Note at the top there’s a little debug line with three bits of data (connection:true or false, current game state, extra info:set when either event fires). Note that the extra data segment shows nothing at all - this gets set when either event is triggered, so for some reason it’s yielding forever.
Below is my coroutine code that continuously fires - the Start() method initially sets it going:
private IEnumerator CheckConnection ()
{
WWW www = new WWW("www.evilegg.co.uk");
yield return www;
if (www.error != null)
{
if (HasConnection && OnConnectionFail != null)
OnConnectionFail (new System.EventArgs ());
HasConnection = false;
yield return new WaitForSeconds(2);
StartCoroutine(CheckConnection ());
}
else
{
if (!HasConnection && OnConnectionSuccess != null)
OnConnectionSuccess (new System.EventArgs ());
HasConnection = true;
yield return new WaitForSeconds(2);
StartCoroutine(CheckConnection ());
}
}
Thanks for any advice
Mat
