- Home /
StartCoroutine() and yield return www does not work with Unity Web Player build
I am using an external WWWForm in a script called SendDataPost.cs that posts data on a server. Here is the code for it:
using UnityEngine;
using System.Collections;
public class SendDataPost : MonoBehaviour {
void Start ()
{
PostData();
}
public void PostData()
{
string url = "http://someplace/somefile/awesome.php";
WWWForm form = new WWWForm();
Debug.Log("started data write");
form.AddField("name", abc);
form.AddField("school", "cdf");
form.AddField("rating", 5);
form.AddField("yes/no", 1);
form.AddField("description", "goals");
WWW www = new WWW(url, form);
Debug.Log("calling iterator now");
StartCoroutine(WaitForRequest(www));
}
public IEnumerator WaitForRequest(WWW www)
{
Debug.Log("started iterator");
// problem area
yield return www;
Debug.Log("yield return done");
// check for errors
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.text);
} else {
Debug.Log("WWW Error: "+ www.error);
}
}
}
And I am creating an Instance of this behavior in another script which is in the game to try and run it:
using UnityEngine;
using System.Collections;
public class Submit : MonoBehaviour
{
// instance of SendDataPost
public SendDataPost postIt;
void OnEnable()
{
Debug.Log("Started");
postIt = gameObject.AddComponent ( typeof ( SendDataPost ) ) as SendDataPost;
postIt.PostData();
Debug.Log("Done");
}
}
Now when I build and run the game as a Standalone exe the data is being posted on the server. But when I build it as a web player the data is not posted. I took care of the crossdomain.xml error. and now I don't see any error but its not working!
the debug statement output is as follows:
Started
started data write
calling iterator now
started iterator
Done
Does anyone have any idea what's going wrong? Any help is appreciated.
Your answer
Follow this Question
Related Questions
Trouble Resuming after Yielding while Inside Coroutine 1 Answer
Multiple Cars not working 1 Answer
Waiting twice inside coroutine (C#) 2 Answers
Coroutine execution not continuing [Solved] 1 Answer
Distribute terrain in zones 3 Answers