public void BuildBuilding(GameObject Prefab, Building Building) { int Index; if (Array.IndexOf(CleanGens, Building) >= 0) { Index = Array.IndexOf(CleanGens, Building); CleanGens[Index].Built = true; } else if (Array.IndexOf(PollutionGens, Building) >= 0) { Index = Array.IndexOf(PollutionGens, Building); PollutionGens[Index].Built = true; } else { Index = Array.IndexOf(PollutionCleaners, Building); PollutionCleaners[Index].Built = true; } GameObject temp = Instantiate(Prefab, Prefab.transform.position, Prefab.transform.rotation); GameObject BPanel = Building.Panel; temp.SetActive(true); temp.transform.SetParent(BPanel.transform); temp.transform.Find("NameText").GetComponent <Text>().text = Building.Name; temp.transform.Find("PropertyText").GetComponent <Text>().text = Building.Description; temp.transform.Find("QuantityText").GetComponent <Text>().text = string.Format("Amount: {0}", Building.Quantity); temp.transform.Find("CostText").GetComponent <Text>().text = string.Format("Cost: {0}", Building.Cost); temp.transform.Find("ProductionText").GetComponent <Text>().text = string.Format("Production: {0}", Building.Energy); BuildingPanel thisBuildingPanel = new BuildingPanel(temp, Building); temp.transform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(Building.AddOne); temp.transform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(delegate { BuyBuilding(Building); }); temp.transform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(delegate { BuildingManager.UpdateBuilding(thisBuildingPanel); }); int CounterThing = (int)Math.Ceiling((Counters[Building.Panel.name] * 130 - 630) / 200d) < 0 ? 0 : (int)Math.Ceiling((Counters[Building.Panel.name] * 130 - 630) / 200d); temp.GetComponent <RectTransform>().localPosition = new Vector3(0f, 250 - Counters[Building.Panel.name] * 130 + 100 * CounterThing, 0); AllBuildings.Add(thisBuildingPanel); Counters[Building.Panel.name]++; UpdateScroll(); }
public void BuildBuilding(GameObject b, Building Building) { //UpdateScroll(); CleanGens[Array.IndexOf(CleanGens, Building)].Built = true; GameObject temp = Instantiate(b, b.transform.position, b.transform.rotation); GameObject BPanel = Building.Panel; temp.SetActive(true); temp.transform.SetParent(BPanel.transform); temp.transform.Find("NameText").GetComponent <Text>().text = Building.Name; temp.transform.Find("PropertyText").GetComponent <Text>().text = Building.Description; temp.transform.Find("QuantityText").GetComponent <Text>().text = string.Format("Amount: {0}", Building.Quantity); BuildingPanel thisBuildingPanel = new BuildingPanel(temp, Building); temp.transform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(Building.AddOne); temp.transform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(delegate { BuyBuilding(Building); }); temp.transform.Find("BuyButton").GetComponent <Button>().onClick.AddListener(delegate { UpdateBuilding(thisBuildingPanel); }); temp.GetComponent <RectTransform>().localPosition = new Vector3(0f, 130 - Counters[Panels.CurrentPanel.name] * 130 + 75 * IdkWhyThisHappens[Panels.CurrentPanel.name], 0); AllBuildings.Add(thisBuildingPanel); Counters[Panels.CurrentPanel.name]++; UpdateScroll(); }