Game Development Reference
In-Depth Information
www.Dispose();
}
// C# user:
IEnumerator WaitForServerResponse ( WWW www,
CallBackFunction callback)
{
yield return www;
if (www.error == null) {
Debug.Log("Successful.");
if (callback != null) {
callback(www.text);
callback = null;
}
} else {
Debug.LogError("Failed.");
}
//Clear Data
www.Dispose();
}
4. Then, we will add the
SaveUserData()
method, which will create
WWWForm
,
set the data, and send it to the server using the
WWW
object. On the last line, we
will use
StartCoroutine
to wait for the server to finish reading the data, as
shown in the following code:
// Unity JavaScript user:
override function SaveUserData ( user : UserData ) {
_wwwForm = new WWWForm();
// Calling PHP for posting score action
_wwwForm.AddField("action","PostScore");
// Encrypt with MD5
_wwwForm.AddField("hash",MD5.Md5Sum(user.name + "-"
+ user.score.ToString() + "-" + _hashKey));
_wwwForm.AddField("score",user.score);
_wwwForm.AddField("name",user.name);