public void JoinGame() { string sPass = joinServerPass.GetComponentsInChildren <Text>()[1].text; string dName = joinDisplayName.GetComponentsInChildren <Text>()[1].text; if (dName.Trim() == "") { joinErrorText.SetActive(true); joinErrorText.GetComponent <Text>().text = "DISPLAY NAME REQUIRED"; } else if (requestedHost != null) { if (!requestedHost.passwordProtected) { netManager.JoinServer(requestedHost, dName); } else { netManager.JoinServer(requestedHost, sPass, dName); } } else { Debug.Log("Something went wrong"); } }
// SERVER LIST void serverList() { int btnW = 160; int btnH = 30; int btnX = 200; int btnY = 200; backButtons(false); if (!Network.isClient && !Network.isServer) { if (GUI.Button(new Rect(btnX, btnY, btnW, btnH), "Host Game")) { ShowMenu(MenuIndex.HostGame); } } if (GUI.Button(new Rect(btnX + btnW + btnPadding, btnY, btnW, btnH), "Refresh List")) { networkManager.RefreshHostList(); } HostData[] hostList = networkManager.GetHostList(); if (hostList != null) { TextAnchor buttonAnchor = GUI.skin.button.alignment; GUI.skin.button.alignment = TextAnchor.MiddleLeft; for (int i = 0; i < hostList.Length; i++) { string serverInfo = hostList[i].gameName + "\t" + hostList[i].connectedPlayers + "/" + hostList[i].playerLimit; if (hostList[i].connectedPlayers < hostList[i].playerLimit) { if (GUI.Button(new Rect(btnX, btnY + (btnH + btnPadding) * (i + 1), btnW * 3, btnH), serverInfo)) { if (hostList[i].passwordProtected) { connectingToHost = hostList[i]; ShowMenu(MenuIndex.JoinGame); } else { networkManager.JoinServer(hostList[i], "asdf"); ShowMenu(MenuIndex.GameLobby); } } } } GUI.skin.button.alignment = buttonAnchor; } }