Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


How to make a simple unity2d inventory system


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Donal Byrne   Members   -  Reputation: 150

Like
0Likes
Like

Posted 22 May 2014 - 11:29 AM

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



Sponsor:

#2 Satharis   Members   -  Reputation: 1677

Like
2Likes
Like

Posted 22 May 2014 - 07:21 PM

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.



#3 frob   Moderators   -  Reputation: 26533

Like
1Likes
Like

Posted 23 May 2014 - 02:01 AM

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.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS