Tips for creating an inventory system?

I have how I could get one to work in my head, but I don’t really even understand how GUI elements work.

I already have the item storage system based on item slot, but I have no on screen representation/choosing system.

Any tips on how I would go about implementing my existing array of Weapons and array of Armors into a clickable inventory system?

C# WOuld be appreciated, since that’s what I’m more fluent in if you provide code

Hey Dothackking,

I bet there is a better way to do this, but I’ll give you tips on how I made mine :smile: Sorry, but I only know java right now :c

Alright, so first, have an InventorySlot texture and save it to a GUIStyle variable. Use this Style to make your inventory grid out of buttons depending on how many slots you want. Once you’re satisfied, create an array of Texture2Ds like so → var InventoryIcons : Texture2D[ ];

Inside this array you need to store all the icons for your items. If you need an idea of how you should make the icons, load up your InventorySlot image in a photo editing software, make a new layer, and draw your desired ItemIcon in the middle. Lastly, just erase the bottom layer and store the new ItemIcon image in your array. I would leave the value 0 in the array empty… For, well — you know, empty slots X)

Now, make an integer array that is the same size as your Inventory. This is where your virtual items are stored. See, when you make the Texture2D array, the value of the texture is basically its “ItemID”. So, the placement value inside the integer array defines the InventorySlot. For example, if you have 36 slots, placement value 14 = InventorySlot 15/ placement value 0 = InventorySlot 1/ etc.

Now the value that is defined in that placement is equal to the item in that slot. So, if:
intArray[5] == 9
and you set 9 in your Texture2D array to a health potion then that means that InventorySlot 6 holds a health potion. Get it? :slight_smile:

Lastly, you’re probably wondering how you make the ItemIcon appear on the InventorySlot. All you have to do is put a line of code above each InventorySlot GUI that draws the texture of the Icon that is inside the specified InventorySlot. This is how it’ll probably look:

GUI.DrawTexture(Rect(Screen.width / 2, 150, 32, 32), InventoryIcons[intArray[0]]);

if(GUI.Button(Rect(Screen.width / 2, 150, 32, 32), “”, InventoryTexture))
{
audio.Play();
}

Alright, that’s just the basics. There is a more complex way to write it where it will all fit within the GUI.Button syntax but I didn’t want to dig you that deep. I’ll let you explore it. You can do so much with this, I promise man. When you click mine, it pulls up the weapon info on the side, an enlarged picture, along with options to equip, drop, hotkey, etc.

Okay, so I’m done. I really hope I helped. I don’t believe I forgot anything! If you run into any problems with it, or if you do want to dig a little deeper, feel free to contact me man! Peace, CTW

well the GUI mainly just needs to know if you either have an item or not, so you could create some bool variables.
then you could send these events upon pickup to update different GUI text, then you could change out the text with some icons or something. you could also to check to see if you already have that item as to make items stack. using integer add
assign a key to call your onGUI to make the GUI appear or not

lots of good GUI info here

GUIScriptingGuide

Thanks for the feedback guys! This had me discouraged, and since it’s a weekend anyway, I decided to take a break for today. I couldn’t figure out how to implement what I was thinking Because I don’t know much about GUI…:

“inv[y] = box with Weapons[×] information in it”

I have built a pretty complex, yet simple system.

I have a wpnSelction panel. Press the wpns selection button, in game, this panel pops open. The game pauses but can still be seen. This panel has a list of weapons you can choose. Some are owned, which can be accessed, some are not. All need ammo, which brings the next phase.

The store can be accessed via a button in the above panel. This store Tweens in over the game scene and wpn selection panel. Here you can buy wpns and ammo, wardrobe and coins for in app purchases (mobile obviously).

How this all works is via a system of managers and delegates that all relate to each other, on way or another.

I have my wpnSelectionMng. It knows the current weapon selected and passes any swapped out weapon’s info. The delegates of this manager are the wpnSelectionBtns. They know thier weapon, the wonSelectionMng, the active player and the icon for itself in the HUD.

Then, there is the storeMng. It is responsible for tweening in a series of panels (visual effect). It contains the itemCardBtn delegates. So, if you want a particular wpn, press it, an info card pops up telling you if you own it, cost and cost of ammo, plus detailing its capabilities.

I hope this is what you are looking for. If it is, all I can really tell you is to strongly consider using a series of managers and delegates to build you system.

My biggest problem was with the GUI part. I’m having no problems with scripting at all, but I couldn’t figure out how to get proper working GUI.

Sorry if I misread your post.

I have stayed away from using OnGUI. It is too abstract for me and is notorious for being a memory gobbler.

For any GUI I like to use EZGUI, as it is designed to be low on overhead, has all types of gestures, commands, functionality built into it already. On top of that, I can see and manipulate the GUI 's elements in the builder. OnGUI, seems so reliant on code.

This is in Javascript but I made a more advanced inventory system tutorial. Not sure if this is what you’re looking for. It’s 8 parts and includes creating an item class, storing them, equipping, ect.

What is this EZGUI? That sounds like exactly what I want…

http://www.anbsoft.com/middleware/ezgui/ but I think NGUI is maybe better. You can also look GUIToolkit if you want a free solution.