Recently we were asked to develop a vertical listview with drag and drop feature in one of our key project called TriviaMake™. TriviaMaker is custom quiz maker that available on Android, iOS, and Web. We have searched on Unity documentation for existing component also there isn’t any custom asset available on unity asset store, so we ended up with developing a custom component for the Unity platform.
As per our requirements, User can rearrange quiz categories with drag and drop gesture. We found some solutions but none of them were perfect and were too buggy. The script which we have developed can work with any type of vertical drag.
So let’s begin to our tutorial by downloading the drag and drop unity script which we developed from github.
Create a sample 2D project.
- Create a parent panel that contains draggable items.
Add Vertical Layout Group on a parent panel for arranging all child in a vertical. Please notice that this method is only for vertical drag and drop.
- Now, Create child items that you will use for drag. Here I created color blocks because those are easy to visualize.
- Add the script to your project.
- Now you noticed that I added the script on my items because I use a full item for drag. You can add a script on a particular button that uses for drag item.
- Now, Bind your item Transform into the CurrentTransform variable. If you use a button for drag then add a script into a button and bind item Transform into the CurrentTransform variable.
So that’s it! Now, Run your project and you can test a complete drag and drop feature.
We At AppTrait Solutions, As a Unity Game Development Company in India, our 2D & 3D unity game developers will help you to develop 2D or 3D games for game lovers. We offer game development services using Unity framework for popular platforms like iOS, Android, Mac, Windows and more