Game Development Reference
In-Depth Information
bool _isLoaded;
string _phpUrl;
public bool isLoaded {
get { return _isLoaded; }
}
public void Initialize ( int maxUser, string
phpUrl) {
base.Initialize(maxUser);
_phpUrl = phpUrl;
}
}
From the preceding code, we created
WWWForm
to send and load the data to the
server. We also created the
Initialize()
function, which will set the maxim-
um number of users that can be displayed on the UI. Also, we set the PHP URL
that will be used for positing and loading data from the server.
3. Next, we will create the
WaitForServerResponse()
function, which will
wait for the server to finish sending the data. In this function, we will use the
coroutine to wait for the server, and then, if there is no error, we will call the call-
back function. Let's add the
WaitForServerResponse()
function to this
class as follows:
// Unity JavaScript user:
private function WaitForServerResponse ( www : WWW,
callback : Function ) : IEnumerator
{
yield www;
if (www.error == null) {
Debug.Log("Successful.");
if (callback != null) {
callback(www.text);
callback = null;
}
} else {
Debug.LogError("Failed.");
}
//Clear Data