We are using C# for our scripts, and I’m trying to get an interface to a web server working using WWW and WWWForm to send some data (like scores), but it’s not working.
I have a method to do the upload:
WWW Post( WWWForm form )
{
WWW www = new WWW( URL, form);
yield return www;
}
If I try to call it like this:
WWW www = Post(form);
// check return value here....
i get a build error (…Post(WWWForm)’ cannot be an iterator block because `UnityEngine.WWW’ is not an iterator interface type)
Based on the docs and other posts, this seems right, but it’s obviously not.
You should just use plain return without yield in the Post function:
WWW Post( WWWForm form )
{
WWW www = new WWW( URL, form);
return www;
}
The yield keyword is for use in coroutines. Coroutines should have the return type IEnumerator and the yield will cause the coroutine to be suspended until the WWW class has finished downloading.
If you want to yield, it has to happen in the coroutine calling the Post method.