// Place defender on mouse down void OnMouseDown() { // Check if there is a selected defender if (!DefenderSelectButton.SelectedDefender) { return; } // get the selected prefab var prefab = DefenderSelectButton.SelectedDefender.DefenderPrefab; // minus the cost of prefab. If no money => return if (!_starManager.UseStar(prefab.GetComponent <Defender>().Cost)) { return; } var defender = Instantiate(prefab, GetSpawnPosition(), Quaternion.identity) as GameObject; defender.transform.parent = Defender.DefenderContainer.transform; // Cleanup DefenderSelectButton.SelectedDefender = null; }