- Home /
Network connecting makes GUI work weirdly
Hi,everyone. I had some problem about network connecting. This is the scene and you can click the button to connect server. And the server is another project and I built it before. The problem is when I click the button it won't call the function 'OnNetworkLoaded' immediately. When I focus on the server window (another project), and back to client window, it works. If I don't focus on the server window, the function doesn't be called. But it connect the server normally.
And more, when I restart my computer, it works normally... one or two times.
Did I do something wrong? Thank you all for reading my problem.
private string remoteIP = "127.0.0.1";
private int listenPort = 10000;
private bool useNAT = false;
void OnConnectedToServer(){
foreach(GameObject go in FindObjectsOfType(typeof(GameObject)))
{
go.SendMessage("OnNetworkLoaded",SendMessageOptions.DontRequireReceiver);
}
}
void OnGUI() {
switch (Network.peerType) {
case NetworkPeerType.Disconnected:
StartConnect();
break;
case NetworkPeerType.Client:
ClientTo();
break;
case NetworkPeerType.Connecting:
Debug.Log ("Connecting...");
break;
}
}
void StartConnect() {
if (GUI.Button (new Rect (10, 50, 100, 30), "Connect Server")) {
Debug.Log ("Onbutton");
NetworkConnectionError error = Network.Connect(remoteIP,listenPort,"UnityNetwork");
Debug.Log(error);
}
}
void ClientTo(){
GUILayout.Label ("Succeed");
}
Answer by thornekey · Aug 04, 2014 at 04:59 AM
Your problem is simple (i hope :S). Your application isnt running whilst you are not focused on it.
Choose the "Run in Background" option. This can be found from
"File>Build Settings>Player Settings>Resolution and Presentation>Run in Background"
Good luck!
no probs. remember to mark the answer as correct for others to see :)
Your answer
Follow this Question
Related Questions
networkview + GUI 2 Answers
Why is networkbehaviour underlined in green? 1 Answer
Multiplayer pause menu won't disappear 0 Answers
On screen scoring in multiplayer 1 Answer