void OnMouseDown() { // if no defender button is selected if (!Button.selectedDefender) { return; } // gets the starCost from Defender script int currStarCost = Button.selectedDefender.GetComponent <Defender>().starCost; // if currency is less than the cost if (StarDisplay.GetStarCount() < currStarCost) { Debug.Log("Not enough sunlight!!"); return; } //deduct the star cost of the current defender StarDisplay.UseStars(currStarCost); GameObject defender = Instantiate(Button.selectedDefender, SnapToGrid(CalculateWorldPointOfMouseClick()), Quaternion.identity) as GameObject; defender.transform.parent = defenderParent.transform; }