Drag & Drop anything in Unity - Inventory/Spells/World Placement/Trading
HTML-код
- Опубликовано: 22 май 2024
- 00:00 Introduction
00:25 Most Important Part Ever..
00:34 Unity Drag & Drop Example Project - game.courses/dragdrop/
02:40 - DragDropThing Script
05:55 - Inventory Example - game.courses/mp/
06:52 - UIInventorySlot
10:10 - Multiplayer Mastery Course - game.courses/mp/
This is one of those tutorials that needs a refresh every couple years as the basics remain steady but the grammar/syntax of Unity means it needs tweaking. As someone who loves playing with the idea of computerized card games - especially the stuff that would be totally unfeasible for physical card games, like "Move all Elves in your deck 1 step closer to the top" or "Each time you play this spell, increase its damage by 5" - I ALWAYS have to know the latest tricks for draggin' and droppin'.
I love how Jason has a Needler just casually sitting on his desk in the background.
This was really helpful. When I tried this in my project another key thing I learned (Copilot helped me) was having to reparent the object as it is dragging so that it can be seen outside the canvas it was currently in. then reparent it to the right canvas after the drag ends so it can be seen correctly
Legend, thanks Jason.
Nice tutorial
Use text instead of image for the drop area. It's a lot more performance-friendly than an empty image when thinking about batching and other stuff. Just a simple empty text component with its collider. Doesn't need any material/font etc. Especially on mobile.
An excellent explanation
Thank you very much, Jason!
Thank you!! This was so helpful.
LEGEND!!!! tnks for this!
Nice! Thanks!
"Be sure to draaaag that mouse down and click the like button or drop a comment" - lol. I see what you did there.
now to combine the items together and design new items
Don't know if it's just me but OnDrag() needs to be like this with my setup:
{
Vector3 screenPoint = Input.mousePosition;
screenPoint.z = 100f; // distance of the plane from the camera
transform.position = Camera.main.ScreenToWorldPoint(screenPoint);
}
Hey, this doesn't work when using a canvas with Screen Space - Camera render mode. What would be a good way to adapt? Thanks!
Hi Jason. Is there any way of making the drag less 'laggy' if moved with speed? On an Android build it can be quite noticeable if using your finger instead of a mouse.
I think what you are encountering is the OS-default how long it take for something to be counted as a touch/drag. Maybe there is a setting in Unity for that, not sure.