- Home /
how to store items in inventory?
I made an inventory trough GUI which consist of a toolbar with 6 windows.... 1.)Tms and Hms 2.)items 3.)Medicine 4.)Pokeballs 5.)Berries 6.)keyItems
ok, the problem is that i don't know how to store items in these ..well how can i save information in these because i only need the name of the object to list inside the window..... i was thinking of making a class for each of the 6 windows ...but i just don't know how to do it ...if any one can point me in the right direction with a script or by suggesting some advice it would be much appreciated.
What do you mean by "store the items in these". Are you talking about the GUI or storing the results of the GUI? It sounds like you are looking for program$$anonymous$$g patterns that might lead to an elegant way to work with the inventory in the game, but please clarify what specific discussion you are after. Also, this may be better off posted to the scripting forum for discussion, unless you can ask a concise question.
ohh ok i mean how can i store the information (name) of items u puck up or u have in the inventory ..and yea store the names on the GUI...well i gess what im asking how can i store information and then read information?
Answer by Rafes · Jul 06, 2012 at 10:46 PM
You should not store information in your GUI. Your GUI should only handle the displaying of, and interaction with, information found in primary objects/managers/controllers (pick your favorite name).
For example, I have an object in 3D space that can be clicked on. It has a single call to my HUD class TargetHUD.Display(this). The HUD knows how to take it from there. They don't need to know about each other or get tangled in shared code.
So, your inventory should probably just display items found in a list in whatever script you use to manage the state of your player. You may want to make an InventoryItem class with basic information that all inventory items will need, which depends on your game, such as wearable slots, like arms or legs, or number of uses, etc. Then you can use a list on your player.
When the inventory comes up, it simply needs to access this list and based on the information, display everything. When changes are made, it should write the changes to the items, or add/remove items from the list.
This is just one possible design pattern. It is very dependent on your game's needs.
O$$anonymous$$G YES :DD ty ...thats what i was asking ...like how do i make the class script that can save info and how can i read that info?
I would just mark this answered and continue on the forums. What your asking is basic code knowledge. For example, I have a script "InventoryItem" and a script "Player" with a list, then i can add InventoryItems to the list. When I launch my inventory for this player, I can read the list and use the items to make my inventory. The details depend on your game. For example, do you have one player, or might you have more? If the inventory should belong to the player, you might want an "Inventory" script on the player gameObject that has the list and also manages any other stuff you might want, like "gold", etc, then your Inventory GUI could read the players Inventory script to initialize the display. I suggest understanding the basics of the code first, then think about how it logically applies to your game. ...and don't forget to click the thumbs up button here when a post or comment helps ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613073818im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
PlayFab: KeyNotFoundException: The given key was not present in the dictionary. 0 Answers
Cannot convert from 'int' to 'PlayFab.ClientModels.ItemInstance' 1 Answer
How to store gameobjects to create an inventory. 3 Answers
First person pick up object and store into inventory? 0 Answers
Text RPG inventory 1 Answer