- Home /
What method should I use for making a drag 'n drop based game?
I want to make a small game that plays similarly to Papers Please. Now I'm debating what the best system for drag and drop is. I could make it based on world space, with normal input detection, the update function, etc etc. Or, I can make it with the EventSystem, but I'm not sure which functions to use in there. Most tutorials say to use IDragHandler and such, but in the API for Unity 2020.x those functions don't exist anymore, although they do work in the engine.
Basically I just need advice. Should I go UnityUI based, or worldspace based? And what functions should I be looking at in case I should go UnityUI based?
I'm making a 2.5d game, so I'm pushed to do it worldspace. I use Coroutines that start on mousedown and stop dragging an object on mouse up. If I start from inventory, I instantiate that object or switch it from UI to world. If it's in the world I just set it to kinematic. When I drop it, I either set it back to kinematic to drop in the world or push it to Inventory. In your case you'd need to position it on UI, you could easily use worldspace movement of that object to follow the mouse with grab offset, which you set on mouse down, so that your object wouldn't stick to mouse with it's center.
Answer by Rechronicle · Oct 17, 2021 at 12:29 PM
Because there is no 'best method', I personally would just go with something that I can work & understand.
There is OnDrag method in UnityUI which could be useful in drag n drop game you're trying to make.