private void ReceivePing() { try { Debug.Log("Searching for Games."); foreach (Transform child in ParentPanel.transform) { Destroy(child.gameObject); } PlayerInfo[] servers = netcontroller.GetServerListFromClient(true); for (int i = 0; i < servers.Length; i++) //for (int i = 0; i < 5; i++) { GameObject goButton = (GameObject)Instantiate(prefabButton); goButton.transform.SetParent(ParentPanel.GetComponent <RectTransform>(), false); goButton.transform.localScale = new Vector3(1, 1, 1); goButton.GetComponentInChildren <Text>().text = servers[i].Name; //goButton.GetComponentInChildren<Text>().text = "Button " + i; Button tempButton = goButton.GetComponent <Button>(); //int tempInt = i; string temp = tempButton.transform.GetChild(0).GetComponent <Text>().text; tempButton.onClick.AddListener(() => ButtonClicked(i, temp)); } } catch (Exception e) { Debug.Log(e.Message); } }
public void ServerSelection() { //string servername = GetComponent<InputField>().text; string servername = selectionText.text; bool serverFound = false; if (servername != "") { try { PlayerInfo[] servers = netcontroller.GetServerListFromClient(false); int index = 0; foreach (PlayerInfo info in servers) { if (servername == info.Name) { netcontroller.ServerSelected(index); serverFound = true; LoadSceneOnClick scenechanger = GetComponent <LoadSceneOnClick>(); scenechanger.LoadByIndex(4); break; } index++; } } catch (Exception e) { Debug.Log(e.Message); } } if (!serverFound) { //invalid name, must choose another descText.text = "Please enter a valid name"; GetComponent <InputField>().text = ""; } }