- Home /
How to Connect Hotbar to Inventory?
I have a hotbar that is somewhat coded... but I'm trying to get it to update before the inventory, and then stop once it's full. So far, I have it updating, then neither will update after about 6-7 items (the hotbar is 6 items). Not sure what I'm doing wrong.
Here is the method where the hotbar updates... I used a for loop
public void UpdateHotbar() { for (int i = 0; i < hotSlots.Length; i++) { if (i < 6) { hotSlots[i].AddItem(inventory.items[i]); } else { hotbarFull = true; hotSlots[i].ClearSlot(); } } }
Answer by Ermiq · Jul 01, 2018 at 06:41 AM
Quite strange code. You're saying the hotbar is 6 items length, so the 'else' part of your code is never reached. In 'for' loop 'i' will be 0, 1, 2, 3, 4, 5 and then loop is closed, so 'hotbarFull' is always 'false' and ClearSlot() is never called.
public void UpdateHotbar() { for (int i = 0; i < hotSlots.Length; i++) { if (i < inventory.items.Count) { hotSlots[i].AddItem(inventory.items[i]); } else { hotbarFull = true; hotSlots[i].ClearSlot(); } } }
changed it to this
Your answer
![](https://koobas.hobune.stream/wayback/20220612165816im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Inventory Drop Function Problem 1 Answer
How to start an inventory system? 2 Answers
GUI focus control - inventory system issue 1 Answer
Toggle Inventory script 1 Answer