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.

30342-problem.png

	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");
	}

Your problem is simple (i hope :S). Your application isnt running whilst you are not focused on it.

30344-ex1.png

Choose the “Run in Background” option. This can be found from

“File>Build Settings>Player Settings>Resolution and Presentation>Run in Background”

Good luck!