public MapSelect(GameObject mapSelectMenu) { state = StateManager.state; gui = state.gui; network = state.network; players = new Text[4]; GameObject playerList = mapSelectMenu.transform.Find("Player List").gameObject; for (int i = 0; i < 4; ++i) { players[i] = playerList.transform.GetChild(i).GetComponent <Text>(); } ownerControl = mapSelectMenu.transform.Find("Owner Control").GetComponent <Toggle> (); roomID = mapSelectMenu.transform.Find("RoomID").GetComponent <Text> (); mapButtonParent = mapSelectMenu.transform.Find("MapButtons"); mapPreview = mapSelectMenu.transform.Find("MapPreview").GetComponent <Image> (); startGame = mapSelectMenu.transform.Find("Start Game").GetComponent <Button> (); GameObject mapButtonPrefab = Resources.Load("Prefabs/MapButton", typeof(GameObject)) as GameObject; GameObject[] maps = Resources.LoadAll <GameObject> ("Maps"); float buttonWidth = mapButtonPrefab.GetComponent <RectTransform>().rect.width; float buttonHeight = mapButtonPrefab.GetComponent <RectTransform>().rect.height; float xOffset = 50f; float yOffset = 50f; float xStart = Mathf.Max((-1 * Screen.width / 2) + buttonWidth, -1 * (buttonWidth * maps.Length) / 2); float xPos = xStart; float yPos = 50f; foreach (GameObject map in maps) { GameObject mapButton = UnityEngine.Object.Instantiate(mapButtonPrefab, mapButtonParent); MapButton buttonScript = mapButton.GetComponent <MapButton> (); mapButton.transform.localPosition = new Vector3(xPos, yPos, 0); xPos += mapButton.GetComponent <RectTransform> ().rect.width + xOffset; buttonScript.init(map.GetComponent <MapData> (), mapPreview); mapButton.SetActive(true); if (xPos > (xStart * -1)) { xPos = xStart; yPos -= buttonHeight + yOffset; } } voteables = mapSelectMenu.GetComponentsInChildren <Voteable> (true); }