public void OnPlotDestroyed(BuildPlotUI plotUI) { if (selectedBuildPlot == plotUI) { UnselectBuildingPlot(); } }
public void UnselectBuildingPlot() { if (selectedBuildPlot != null) { selectedBuildPlot.onBuildButtonClicked -= OnBuildButtonClicked; Destroy(selectedBuildPlot.gameObject); selectedBuildPlot = null; } }
public void SelectBuildingPlot(BuildingPlot plot) { if (selectedBuildPlot && selectedBuildPlot.buildingPlot == plot) { //Do nothing if it's the same plot return; } if (selectedBuildPlot != null) { UnselectBuildingPlot(); } GameObject plotGO = Instantiate(buildPlotUIPrefab, Camera.main.WorldToScreenPoint(plot.transform.position), Quaternion.identity, canvasTransform); plotGO.name = "SelectedBuildPlotUI"; selectedBuildPlot = plotGO.GetComponent <BuildPlotUI> (); selectedBuildPlot.onBuildButtonClicked += OnBuildButtonClicked; selectedBuildPlot.onBuildPlotDestroyed += OnPlotDestroyed; selectedBuildPlot.Init(plot); }