I want to make sure to get time from internet ?
My function it’s work when internet connected but internet lag it’s return -1.
I asked developer who advise me. He said
I want to make sure to get time from internet ?
My function it’s work when internet connected but internet lag it’s return -1.
I asked developer who advise me. He said
IEnumerator DownloadThing(string fromHere, string toHere){
Debug.Log("downloading thing from " + fromHere);
WWW www = new WWW(fromHere);
yield return www;
if (www.error == null)
{
Debug.Log("downloaded data : " + www.text);
toHere = www.text;
}
else
{
Debug.Log("ERROR: " + www.error);
}
www.Dispose();
www = null;
}
StartCoroutine(DownloadThing(fromHere, toHere));
fromhere being a URL to the thing you want to get and
toHere being a variable which will be accesible by the coroutine. I just use a field.
A few things to note on his script…
If toHere is a global variable, you don’t have to pass it in to the coroutine.
Also, if -1 is a return value, you’ll need to check for it and then do a yield and call the coroutine again. But make sure that it’s not an error, in which case www.error will not be null, thus you would start the coroutine again in the else.
If you are trying to set a limit on number of calls, which is a good idea as was suggested to you, you’ll need a global variable that you increment and check before you call the coroutine again.
Since you contacted a developer, are you using an asset? Sometimes services have their own api setup to get stuff like this done a bit easier.