Jump to content
  • Advertisement
Sign in to follow this  
Donal Byrne

Unity How to make a simple unity2d inventory system

This topic is 1667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Trying to make a VERY simple inventory for unity2D. I would like to be able to pick up objects, drop them and have them fill up an inventory screen.

 

Can be made in either JS or C#

 

Thanks

Share this post


Link to post
Share on other sites
Advertisement

This question would probably best be asked on a Unity related forum, I don't have Unity experience in particular but a bit of advice about a generic inventory system.

 

Usually an inventory is little more than an array/collection of references to game objects, the actual implementation of building the inventory itself doesn't have anything to do with graphics or the platform really. Usually you'd make a class that represents an inventory, it'd have specific "interface" methods that allow you to interact with the inventory(sort it, add items to it, remove items, get an item in a particular slot) and your player object or something may contain an inventory object as part of its definition.

 

The only real part that would really be different in unity would be the graphical aspect, this varies a lot based on the game. For instance if you wanted to do something like Minecraft or a typical MMO or something where you have a "slot" based inventory where you drag pictures around, then you'd have an object representing an image slot of an item that could be dragged between slots in an inventory gui window, releasing an item would instruct the inventory to move the item(in code) so on, so forth.

 

The mechanical backend of any inventory will be similar across the board however, that should give you an idea of where to begin looking at least.

Share this post


Link to post
Share on other sites
As he wrote, it is just a collection.

You could store references to the individual GameObject items in a collection. Or you could store references to the prefab accompanied with a count of those items. Or you could just store a count of items in an array and then use a lookup table to figure out which prefab is associated with the array index. Or you could do something else entirely, whatever you dream up.

For the graphics associated with the items, you could build your own base class that uses some function or even a public variable to get the desired Texture2D associated with it, so instead of storing the base GameObject you store the subclass object and then use the accessor, which you could name GuiTexture or whatever else you wanted.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!