I am trying to get the following working, with some modifications, and in C#:
http://unity3d.com/support/documentation/ScriptReference/WWWForm.html
The code works when its in the Start function, however I would like to load a few files in sequence, so moved the code to its own function, and that’s when it stopped working:
void Start()
{
Debug.Log("readPlayerData");
//StartCoroutine( readPlayerData(dataUrl));
readPlayerData(dataUrl);
}
private IEnumerator readPlayerData(string dataUrl)
{
string playName = "Player 1";
int score = -1;
// Create a form object for sending data to the server
var form = new WWWForm();
// Assuming the script manages for different games
form.AddField("game", "MyGameName");
// The idof the player
form.AddField("id", playerObject.myID);
// The score
form.AddField("score", score);
// Create a download object
WWW downloadW = new WWW(dataUrl, form);
// Wait until the download is done
yield return downloadW;
if (downloadW.error != null)
{
Debug.Log("Error downloading: " + downloadW.error);
}
else
{
// show the data
Debug.Log("DATA: " + downloadW.text);
}
}
I would guess it has something to do with the yield and IEnumerator code… The code runs, but it seems to just stop indefinitely when it gets to the yield, and doesn’t even time-out…
Ideally I would like to call the function multiple times using the StartCoroutine, but I think getting the above to work first would be logical.
Maybe its just some basic C# knowledge that I am missing, so any help would be appretiated.