public void TileSelected(TileScript tile) { var canDestroy = tile.CanDestroy(); var buildingUpgrades = tile.AvailableBuildingUpgrades(); var clickUpgrades = tile.getClickUpgrades(); foreach (var oldGameObject in _upgradeButtons.Keys) { Destroy(oldGameObject.gameObject); } _upgradeButtons.Clear(); if (canDestroy || buildingUpgrades.Count > 0 || clickUpgrades.Count > 0) { gameObject.SetActive(true); destroyButton.gameObject.SetActive(canDestroy); foreach (var buildingUpgrade in buildingUpgrades) { var newButton = Instantiate(upgradeButtonPrefab, transform); newButton.GetComponentInChildren <Text>().text = buildingUpgrade.Next().name; var button = newButton.GetComponent <Button>(); AttachTriggers(button); _upgradeButtons[button] = buildingUpgrade; } foreach (var clickUpgrade in clickUpgrades) { var newButton = Instantiate(upgradeButtonPrefab, transform); newButton.GetComponentInChildren <Text>().text = clickUpgrade.Next().name; var button = newButton.GetComponent <Button>(); AttachTriggers(button); _upgradeButtons[button] = clickUpgrade; } _selectedTile = tile; } else { gameObject.SetActive(false); } }