Selecting the towers
If you remember, all the trading operations have a selected tower to deal with. In fact, when the player presses the sell button, the game should know which cupcake tower the player intends to sell. As such, the player should be able to select (and unselect) a tower, and this tower should notify the trading system.
To achieve this, we need to slightly modify the CupcakeTowerScript
. From the previous section, we know that when the tower is active, it has a collider to prevent placing other towers on top of it as well. But, we can also use this collider to detect if the player clicks on this very specific tower. In particular, we can use the self-explanatory function, OnMouseDown()
in the following way:
//Function called when the player clicks on the cupcake Tower void OnMouseDown() { //Assign this tower as the active tower for trading operations TradeCupcakeTowers.setActiveTower(this); }
After saving the script, the player is able to select...