- Home /
How to go around creating inventory with new GUI (4.6 Beta)?
I know how to make an inventory system using arrays and other methods, what im really asking is if anyone knows how to go around using the new gui system to display my array of objects in the gui. What functions are there to script with new gui ? Since i noticed the new gui is quite a bit different when talking scripting wise. please help , thanks
Here is a great tutorial, that shows you how to create an inventory with the new 4.6 UI: https://www.youtube.com/watch?v=$$anonymous$$LaGkc87dDQ
Answer by Alessio89 · Aug 22, 2014 at 03:15 PM
If you ever used nGUI you'll feel at home. Mostly. Basically you have various built-in gui elements which you can access from GameObject -> UI. Those have some basic functionality like showing images, texts, scrollbars, button and many more.
Every element has to be child of a Canvas. If no canvas are in the scene when you first create an element, a canvas will be created and the element will be parented to the canvas.
In the canvas you can choose from three different modes: Screen Space - Overlay, Screen Space - Camera, World Space. What this means is that you can choose to place your GUI on top of the scene OR in World coordinates (which is awesome, really).
To make an Inventory, you would need to code some sort of grid sorting yourself.
hint hint: the relation between an index value and the position in the grid is:
index = x + (y*gridWidth)
Now you want to head over here -> 4.6 UI Beginner tutorial and learn the basics of the system. Specifically you want to learn about ScrollRects and Masks.
Last thing: if you want to access all the new unity ui classess, you'll have to either specify a using statement like so
using UnityEngine.UI;
or call every elements by namespaces like so
UnityEngine.UI.Button button;
If you mess around with the system after watching the basic tutorial, you'll surely get a lot of stuff and will be able to ask more precise questions about the inventory system. :)
You don't have to write your own grid sorting, becouse there is a built in version. You can find it in Component/Layout/Grid Layout Group. I got only one problem with this, the size of the grid elements are not changing with the canvas.
Oh now I feel stupid for writing my own grid sorting component. $$anonymous$$eh. Good to know :D