Line 7 does a busy-wait for the request to complete. Depending on the WWW implementation (which varies between platforms), the request may or may not be able to complete in the background - on some platforms it requires your code to return control to Unity. So you need to avoid busy loops like that - they are really bad practice anyway.
The easiest way to resolve this is probably to move all of the response to the button getting pressed into a coroutine. Then that coroutine can yield waiting for the request to complete, without blocking OnGUI. Something like this:
if(GUILayout.Button("Create Channel", GUI.skin.button)) {
StartCoroutine(DoCreateChannel());
}
...
private IEnumerator DoCreateChannel() {
string urlRequest = "http://mywebsite.com/game/AddChannel.aspx?ChannelName=" + ChannelName;
WWW request = new WWW(urlRequest);
yield return request;
string result = stripString(request.text);
int channelID = int.Parse(result);
if(channelID != 0) {
Message = "Channel Created!";
} else {
Message = "Channel Name already exist!";
}
}
If you need some of the processing to be encapsulated elsewhere then you can do that but it's best if the WWW request itself is handled here. Otherwise you end up needing to chain coroutines together, and you quickly reach a point where pretty much every function involved has to be a coroutine, and it's all badly coupled.
↧