Unity Tutorial - Drag & Drop Tutorial #1 [RPGs, Card Games, uGUI] - c4gamingstudio.com

Unity Tutorial – Drag & Drop Tutorial #1 [RPGs, Card Games, uGUI]

Views: 377526
Like: 4308
Make sure to SUBSCRIBE so you don’t miss a video!
Download the complete project:
Also, please feel free to ask lots of questions in the comments.

This channel is mostly all about game programming tutorials, specifically with Unity 3d. You may also be interested in my primary channel, where I play and review games:

I can be reached at:
[email protected]


  1. can you use this on objects that are not in the UI? If not, how would you drag something from the UI and drop it in the world space?

  2. I have a question: i al developing The cards con photoshop, how can i export them To unity? Or cannot do it?

  3. Nice one … Superb For Beginners and easy understandable…

  4. if anyone's still using this & needs the simple solution to add the offset mentioned at @23:43:

    public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
    Vector2 offset;

    public void OnBeginDrag(PointerEventData eventData)
    offset = transform.position – new Vector3(eventData.position.x, eventData.position.y, 0);

    public void OnDrag(PointerEventData eventData)
    transform.position = eventData.position + offset;

    public void OnEndDrag(PointerEventData eventData)

  5. will this work for android touchpad as well?

  6. Quill18, I remember that name. What did you do on YouTube a few years ago, was it league?

  7. This is perfect just what Im looking for 😉 will this work on mobile devices as is (without the need to change the code)?

  8. If anyone wants to know how to make it draggable from any position, just do something like:

    Vector2 dragOffset = new Vector2();
    public void OnBeginDrag(PointerEventData eventData)
    dragOffset = (new Vector2(this.transform.position.x, this.transform.position.y) – eventData.position);

    public void OnDrag(PointerEventData eventData)
    this.transform.position = (eventData.position + dragOffset);

  9. i wish i had some money to pay people to do this for me this is going to take a awhile

  10. Any idea of assembly simulation where you drag objects where they should be placed properly. somehow like pc assemble simulations.

  11. 12:54 did you say "embiggen", well it's a perfectly cromulent word.

  12. Is there a way to change the button pressed to drag?

  13. Any advice on using this same script for 3D objects?

  14. "now if i just click on the black lotus nothing happens, but if i click and hold and than move to the side, still nothing is happening." (SAVAGE)

  15. Can I use it to drag and drop an object in android application?

  16. Quill, thank you very very very much.
    I was just about to give up on doing my card game, because i couldn't find anything that was really useful and i was veeeery lost, so i started to lose motivation. But now i found this video and i am finally starting to understand a lot of things and i am as motivated as ever again. So thanks a lot =D

  17. Learnt alot! Good video by-the-way ! =)

    By the way, is it ok if i can get your advice on these android app below? I am still a beginner and hope to learn from everyone. Your feedback is greatly appreciated!…

    You can search ' pub:Path Ahead ' in Android Play Store (P & A are case sensitive).

    Thank-you so-so-so-much !!

  18. Can unity be used on Mac? I wanna make my own card game, but I don't know what to use or if it ca be used on my Mac computer. Little help would be amazing. Thank you.

  19. Fantastic video. Love the pace and level of detail you go into. Liked and subscribed!

  20. Sad doesnt work in 2019 (Unity 2018.3.11f1):(
    I tryed to implement it on my Card Game but it just do nothing.
    Than I downloaded your Project, but same problem.

  21. We use to do it with just one image and a list of polygon points for each "hot area" before things got complicated building solutions that fit many different platforms and more sexy graphics.

  22. thx for your videos <3

    For offset, this code work if someone need. Work for me 🙂

    Vector3 offset;

    public void OnBeginDrag(PointerEventData eventData)


    offset = transform.position – new Vector3(eventData.position.x, eventData.position.y, 0);


    public void OnDrag(PointerEventData eventData)


    transform.position = new Vector3(eventData.position.x, eventData.position.y, 0) + offset;


  23. There is a way to make the object be always in the exact mouse point instead of "following" that point when you move the mouse around like in the video?

  24. hi sir

    sir can i ask a favor?
    can you help me out with my project im using unity as the main platform for our project..

    reply sir asap..thanks

  25. but how did you design that game UI you used at the beginning of this tutorial. please we need a video on that. thanks

  26. Where can I find the 00:00 Drag and Drop mechanic? That's exactly what I'm looking for and I have no experience in it. Thanks!

  27. I havent watched the 2nd part yet so i don't know what you are proposing yet but the way i would do it is to make the Drag Start function save the original location and make the Drag End function check if it is colliding with a slot it can go into and then if it does set it to the slots position and if it doesnt set it back to the original location

  28. PLEASE can you remake this tutorial with a grid system? As opposed to making a separate canvas for each of my grid tiles.

    And if you manage it so items bigger than 1 tile could be dropped onto the grid (like a city builder) that would make all my dreams come true.

  29. What version of unity were you using when you made this?

  30. somehow, the sprite i'm trying to drag disappears and never comes back after I trigger OnDrag. did it happen to anyone else? can't fix it, googling didn't help. I tried rearranging objects in canvas so that my bg image is upper in hierarchy than the sprite i'm intending to move, but it disappears anyway 🙁 please help

  31. Nice tutorial. Just something to keep in mind, layouts (Grid, horizontal, vertical) want to keep a certain vertical or horizontal pixel count which tends not to work well when changing screen resolutions.

  32. hi there! i try to drag the card from the canvas "hand" to an cube // i want to make an table with many drag fields. but i hang a little bit 🙁 hope any one have a tip

  33. So im messing with this code for this first part and if you move your mouse fast enough, the card can fling off screen, I think its funny and I dont know why.

  34. dude, to be perfectly honest I am glad that you didn't edit out the mistakes. Learning and following these kinds of tutorials is one thing, but seeing troubleshooting in action and then understanding why the problem occured in the first place is significantly more valuable than being given a step by step instructional on how to do something! Thank you so much!

  35. i'm hoping these videos will help me create the card game i want to make. I'm going for something similar to Yu-Gi-Oh and Pokemon tcg but in what looks like a battlefield kind of layout. So I hope your videos will also provide how the npc functions. I want to make a card game that can be PvP, PvE, and co-op. PvE referring to you vs. an npc instead of an actual player.

    btw, thank you for the video! I recently learned JavaScript so this C# coding you made actually makes sense to me based on what everything is meant to do in your script! My only challenge now will be making the digital art for the pics of the cards as well as the backgrounds.

  36. Greate video. Keep making these small errors :p they are quite educational

  37. Thanks very much, even six years still usefull!

  38. Question: This works fine for UI images and such. but it doesn't work on prefab gameobjects for some reason, is there anything else I need to do for that?

  39. Is there any way to drag just a floating copy of the card, and not the actual image?

Leave a Reply

Your email address will not be published.