Game Development Reference
In-Depth Information
Adding 2D button behaviors
Now that we can stock our shop and purchase items from it, we just need the ability for
users to buy items when selected, so create a new script named
BuyButton
and place it
in
Assets\Scripts\Shop
with the following contents:
using UnityEngine;
public class BuyButton : MonoBehaviour {
void OnMouseDown()
{
ShopManager.PurchaseSelectedItem();
}
}
The preceding code simply calls the static
Purchasing
function we created in the
ShopManager
script earlier to buy an item on any game object that has a 2D collider
placed on it, as we did with the
ShopSlot
script.