Game Development Reference
In-Depth Information
public void SetShopSelectedItem(ShopSlot slot)
{
SelectedShopSlot = slot;
PurchaseItemDisplay.sprite = slot.Item.Sprite;
PurchasingSection.SetActive(true);
}
Then, we add the ability to clear the selected item from the shop using the following func-
tion:
public void ClearSelectedItem()
{
Debug.Log("Clearing Shop Purchase area");
SelectedShopSlot = null;
PurchaseItemDisplay.sprite = null;
PurchasingSection.SetActive(false);
}
Finally, we add the ability to purchase the currently selected shop item using the following
function:
public static void PurchaseSelectedItem()
{
SelectedShopSlot.PurchaseItem();
}
Each of the preceding functions is self-contained and controls each of the steps necessary
to perform each action. They do so by enabling or disabling the screen elements, such as
PurchasingSection , to perform actions on dependent objects such as the shop slots.
You will note that this last function is also set as static . This is to enable it to be ac-
cessed from anywhere in the code without referencing it or performing GetComponent
for the ShopManager script.
As stated in the previous sections, it might seem like you could make everything static
and avoid using GetComponent altogether. However, using statics has certain over-
heads and can lead to a messy and hard-to-diagnose code; it should not be overly used. If
in doubt, don't use it, unless necessary.
Search WWH ::




Custom Search