Hi Chris,
Happy Holidays.
I'm trying to implement an inventory system similar to this one.
https://prnt.sc/S4ivc5NGw3ky
I have created the new UI prefab, and it looks like this:
Canvas
└── Panel (Background)
├── ItemName (Text)
├── ItemBorder (Image)
│ └── ItemIcon (Image)
└── Description (Text)
I'm having difficulty linking it to the AC Inventory menu. Will I need a custom script for that?
Thank you,
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
A custom script may be necessary for the name/description to appear, as the description would be a String Property associated with each Item.
For the Item display, however, you'll first need to set your Menu's RectTransform boundary to Panel (which should span the visible portion of the Canvas).
You can remove the default ShiftLeft / ShiftRight buttons if you have no scrolling buttons in your UI. If you want to keep them, add two Buttons to the UI prefab and map them to the elements. A tutorial on this can be found here.
For the items themselves, you'll need to duplicate your ItemBorder / ItemIcon objects as many times as you want items to be displayed. Each ItemIcon will need to have a Button component associated with it.
Then set the Items element's Max number of slots property to this number, and assign each ItemIcon to each slot in the Menu Manager. Again, see the tutorial for details with this.
For the Description: create a new String Property named Description in the Inventory Manager, so that you can then enter in Description text for each Item. I can assist with getting this displayed in the Menu, but it's important to get the above working first.
Thank you for the explanation, Chris. I implemented the inventory, and my friend assisted me with the script. Here is my current setup.
https://prnt.sc/tdE8gz6eHjWj
https://prnt.sc/H2IhjZ1Iej6z
https://prnt.sc/hgskro1NPNxd
https://prnt.sc/QdMo6LN63aA8
https://prnt.sc/nCSUlXLcRp1a
https://prnt.sc/8TPHg-2yu_X2
https://prnt.sc/fJhOLQA3pIHn
However, I'm facing two issues:
1) When using the mouse, the inventory works, but when I use the keyboard, I get this error: https://prnt.sc/NVHLxfSDkfnH
P.S. The mouse should not be functioning because it is supposed to be disabled.
2) Item name and description do not appear even though I created a label in the NewItem menu. I keep receiving this error: https://prnt.sc/Nvc1PJrRRe_0
OnInventoryAdd actionList: https://prnt.sc/-T4HZ4gOci6N
First selected item script: https://prnt.sc/DH0-TeABt2MY
Handle inventory interaction script: https://prnt.sc/GYqlQPibb-mt
You've got "btnSlot1" as the Menu's RectTransform - set this to Panel instead.
Check that the objects that have the script attached have a RectTransform component attached, but the error is from your custom script.
It's looking for an element named "Lable" - it's instead named "Label".
Unfortunately, adding the script made things complex for me, as I keep encountering all sorts of problems. I decided to try your UI prefab, but I have a few questions.
1) How do I replace the green item highlight with a banner? When I change the colour tint in the inspector to Sprite swap, it only displays the highlighted banner instead of the inventory item.
https://prnt.sc/PJC2dw0rDA5w
https://prnt.sc/51yUQ3zYxFCl
2) How do I add a sound effect for selecting the incorrect inventory item?
3) How can I restrict inventory scrolling to only available items?
4) I disabled the inventory cursor in the AC cursor settings but can still use it to interact with the inventory. How do I completely disable it?
You can set the Button component's Target Graphic to the Image that displays the item's icon to have it tint that instead of itself. Alternatively, you can assign a separate "Active graphic" per-item to have it appear differently when selected.
How are you defining an item selection as "incorrect"?
If you're referring to an invalid Hotspot/Item combination, you can define an "Unhandled inventory" interaction in the Hotsot component that runs a Sound: Play one-shot Action to play a sound if an Item is used on a Hotspot when no "Inventory" interaction is defined for that specific item above it in the Hotspot Inspector.
Is this for an Interaction menu, i.e. one that appears upon clicking a Hotspot to let the Player choose which item to use on it? This is a case of using the "Choose Hotspot Then Interaction" mode of interaction, and the default Interaction menu rather than Inventory - see the 2D Demo as an example of this play style.
Set the Inventory box's Inventory box type to Hotspot Based, and check Only show items referenced in Interactions?.
If the Menu doesn't pause the game, use the Engine: Manage systems Action to allow for in-game direct control of Menus.