Game Development Reference
In-Depth Information
private int nextSlotIndex = 0;
}
When the player enters the shop's screen, we want to be able to display the current shop
owner and a selection of their wares. So, when ShopManager starts, we need to config-
ure those items as follows:
void Start () {
var OwnerSpriteRenderer =
ShopOwnerLocation.GetComponent<SpriteRenderer>();
OwnerSpriteRenderer.sprite = ShopOwnerSprite;
OwnerSpriteRenderer.transform.localScale = ShopOwnerScale;
if (ItemSlots.Length > 0 && ShopItems.Length > 0)
{
for (int i = 0; i < ShopItems.Length; i++)
{
if (nextSlotIndex > ItemSlots.Length) break;
ItemSlots[nextSlotIndex].AddShopItem(ShopItems[i]);
ItemSlots[nextSlotIndex].Manager = this;
nextSlotIndex++;
}
}
}
Here, we just took the configured sprite for the shop owner, assigned it to SpriteRen-
derer , scaled for the relevant game object, and then looped through all the available
slots in the shop and picked out items from its inventory to place in them, ensuring we
only stock as many items as the shop can handle.
You will notice that the last function actually has an error. This is because we did not add
the actions/behaviors for the ShopSlot folder. We will fix that shortly.
Next, we need some helper functions that represent the actions/behaviors that the shop is
capable of performing; first, we add the ability to select an item for purchase using the fol-
lowing function:
Search WWH ::




Custom Search