Ok so I’ve seen this in other games but I don’t know what this kind of shop system is called. Off the top of my head I’m trying to make a shop system like in undertale or deltarune. Like where you go in to a shop, game takes you to another scene where theses a dialogue box with options on the side. How would I go about doing this please help
If I was programming this, I would first start by figuring out how to make something that looks how I wanted it to, even if it wasn’t functional. If you don’t know how to do this, I would look up tutorials on creating GUIs. Then I would set up a system for storing the items in the shop. This will be easier if you already have a player inventory, but if you don’t you’ll need to set that up too, and either way, I would recommend using a similar data structure for both. So, in the simplest case, your inventory could be an array of items. I would recommend creating an ItemStack class that looks something like this:
public class ItemStack {
public readonly string name;
public int count;
public readonly int price;
public Item(string name, int count, int price) {
this.name = name;
this.count = count;
this.price = price;
}
}
I would actually recommend using an enum
to represent item types instead of strings, but if you don’t know how to do that, don’t worry about it.
Now you can use a List<ItemStack>
to store all the items in the shop, and the items in your inventory.
Then you can use some text box in your display to show all of the item names by iterating through the list. You can then use an int to represent which item is currently selected and increase and decrease it when you press some inputs. Then you just make it so that when you press some confirmation key, if you have enough money to buy the item that’s currently selected, you reduce its count by one in the shop, reduce your money by its price, and put it your inventory.