Best way of doing inventory in UI
Hey! Is it ok to use collision boxes in UI to check if one item is on top of another item? (Inventory system) Or is there another way to check if an item is on top of another item in UI. I want to know the best way of doing this because it's an inventory system and I don't want an inventory system taking up computer juice if ya know what I mean haha
@Breaking_Reality - Hi - to me it sounds like you haven't done even the basic research into topic.
If you google for it, you come across multiple tutorials, youtube is full of them. None of these will give you fully working system (probably) but will $$anonymous$$ch you the basics what and how you should do. I've been learning how to create inventory system, it will boil down to how you'll manage your events and related things - are you just going to use clicks to add/remove items, or maybe drag and drop, and are you going to also drag world items to inventory and so on. $$anonymous$$aybe you'll allow stacking of items, or swapping items from slot to slot... Depending on these, you'll have to consider different UI system, event system and raycasting related issues.
Also, Unity manual has an example of drag'n'drop using UI system, although I find it pretty convoluted for an example.
Unity UI system scripts you create, can implement UI events, Like BeginDrag, PointerEnter and so on - these might be little hard to find at first, but there are many posts on these, now that you know what to search for: https://docs.unity3d.com/ScriptReference/EventSystems.EventTriggerType.html
@eses Actually I spent 2 days looking for the best way of doing it for my games inventory. Collisions is something I wanted to avoid and I found the IDrag extensions but I was still struggling on how to know if the mouse was over some parts of UI. I used the eventsystem pointer things you mentioned but I didn't know how to write it properly I started with something like this one line of code EventSystem.current.RaycastAll() with some random parameters and well it didnt work. I gave up on it because I didn't find Great documentation and examples on it online. Then I found someone on some janky website who managed to get it right using evensytem and raycasting. I used that and it worked. With like 8 lines of code it returned a list of were the mouse was at. Then I just needed to get the IDragHandler, IEndDragHandler in the code and walla I got it to work when I wanted it too. The next issue was knowing what slot had what and creating things like if that slot had an item alreay that ment the user wanted to switch the items slots. I written this who thing and it worked but it was messy and some things didnt work exactly how I wanted with some random bugs in it too. I was forced to re - do the inventory code 3 times and now I finally got something I REALLY LI$$anonymous$$$$anonymous$$ Since Im new the other tries were messing with code all over the place. I decided I should have a hotbar manager and Drag/Drop code on the UI elements and the hotbar manager would add/remove/switch the items the user is dragging/dropping around in their inventory and I also have a Inventory $$anonymous$$anager and a HotbarSlot scrip that goes on all the hotbars so that I can just call the inventory manager and ask for an item in hotbar slot 1 etc or remove an item in hotbar slot 9 etc. I decided not to go on youtube because I felt like I needed to learn it by reading online and just experimenting. Though it took 4 days in total I got it working very nice and I accomplished doing it myself with a little reading and poking around in threads online. Thank you for your help but you are a little too late. Now I know looking on youtube might save me alot of time and I shouldnt be ignoring these great sources that can help me alot. I guess I did this because I wanted to actually learn and not forget something all the time like I would if I watched a youtube video. I'm afraid I do too much of it sometimes. Thank you though and I will mark you as best answer because you explained everything I did in my code.. just a little too late for me haha!
Your answer
Follow this Question
Related Questions
One textUI and two colliders that update it 0 Answers
Particle System Collision with UI 0 Answers
How can I create a VR world space touch-screen input system? 0 Answers
Display list as UI or GUI 0 Answers
Why is drag and drop not working? 1 Answer