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. If anyone is curious about how to create a "smooth" drag instead of one locked to the anchors, this is the solution I implemented to achieve that effect.

    Vector2 mousePosition;
    public Vector2 difference;
    Vector2 currentPosition;
    public float smooth;

    void Start() {
    smooth = Time.deltaTime * 420;

    public void OnBeginDrag(PointerEventData eventData) {
    currentPosition = this.transform.position;
    mousePosition = eventData.position;
    difference = mousePosition – currentPosition;

    public void OnDrag(PointerEventData eventData) {
    position = GetComponent<RectTransform>().anchoredPosition;
    this.transform.position = eventData.position – difference;

  2. Thanks a lot . I was searching that Tutorial from great time . You solved my Biggest Problem .

  3. With offset:

    public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {
        public Vector2 dragOffset = new Vector2(0f, 0f);

        public void OnBeginDrag(PointerEventData eventData)    {
            dragOffset = eventData.position – (Vector2)this.transform.position;

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

        public void OnEndDrag(PointerEventData eventData) {
    // …

  4. Great job with this tutorial! I usually can't stand when people present tutorials and they run into issues like you did. However, I appreciate when coding tutorials do because there's so many errors you can run into without realizing what the heck is going on. Great enthusiasm, great explanation, great tutorial overall.

    Liked and subscribed!

  5. Hello can you give me the source for the pre made example? on the first part of the video

    EDIT: Found the example. Anyway love the tutorial 😀 you added some code exploration thing on it. Which is nice. I like it

  6. I've been subscribed to your gaming channel for some time now, glad to finally find out that you have been doing coding tutorials as well.

  7. Excellent stuff. it works well. Question: do you know how I can access the position of each hand. I am creating a scramble-word-sentence and the user must drag and drop the words in the right order.

  8. how can i create a multiplayer card game
    on LAN

  9. Hello! Your tutorial is very helpful but there is an issue within my game. In order for the image on my card to show in unity's game mode my canvas has to be on "Screen Space – Camera". This is an issue because in your tutorial you use "Screen Space – Overlay". So when I use the script it pushes my card really far out from the camera's view when dragged. Is their a way I can lock the space it is able to drag and keep my image at the same time?

  10. OMG – I had no idea you can hold alt or shift to change the auto-anchors! There are a few things I've been upset don't exist and I've had to do manually, but they do exist and are just 'hidden'.

  11. I just pause at the wrong point and try and try and try……..

  12. I just pause at the wrong point and try and try and try……..

  13. I wrote exactly your code, but the functions don't get triggered. There is no message and no movement. Can someone help?

  14. أصدقاء الشطرنج العربي says:

    does the object have to be a UI? it doesn't seem to work for me with normal objects..the drag handler is not doing anything
    here's the code in case it doesn't have to be a UI:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.EventSystems;
    public class draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {

    public void OnBeginDrag (PointerEventData d) {


    public void OnDrag (PointerEventData data) {
    Debug.Log ("working");
    this.transform.position = data.position;

    public void OnEndDrag (PointerEventData d) {


  15. Does it change a lot if you do it in javascript?

  16. just looked through your channel and it seems to have many tutorials i'll need, i might be drunk as all fuck but you just earned yourself a new sub 😉

  17. Duuude.. Finally i know how unity works… Thanks sooo much 🙏

  18. Thanks dud, very easy to understand, you talk a bit too fast though 🙂

  19. Hello, can you help me a bit, I follow your instruction but my object just flew away ??

  20. sir can you do the same example like dumb ways to die ?

  21. Hey buddy i have to do a system drag and drop but a i need to do works with a game object do you have any segestion for that?

  22. I hope I can follow your tutorial, i will try

  23. Thanks for not locking your tutorials behind a pay wall. Seriously, it saves me a lot of stress trying to make a complex TCG simulator.

  24. will this work if i use android platform?(Will the DragEvent respond to touch)

  25. The card just disappears when I try move it for me… although it does say that its dragging in the console, even if i cant see it. :/ any help?

  26. Your voice sounds a lot like Brian Kibbler's

  27. I did the same with your instruction but when I dragged the image lost. thanks

  28. I have a question where can i find the unity demo. can you provide an URL?> the one at the very start of the video.

  29. I followed everything in this Video to see if this will still work, but for some reason, as soon as i drag something around it dissapears into nowhere 😀 In the inspector the positions goes nuts, crazy. Maybe if someone read this, maybe even you quill, i would be happy to understand whats happening ^^

  30. Ok there seems to be a bug with my program. I have no clue ,but it does the dragging thing ,but It drops my feel like (-4,-4) is distance from the card.( way lower left). I probably should try a different way or something like that. I am using the personal version and it's up to date.

  31. Thanks a bunch, this is an excellent tutorial, you don't waste any time, everything is useful and you know how to say things in order for me to understand.

  32. it works easy and fast on a UI Image, but why doesn't this work on a 2D Sprite gameOjbect;

  33. Sincerely liked this. You're awesome at explaining, and, for the first time, I'm so sorry I can't donate to someone as talented as you. Also, so "human-ish" to be "improvising", trying to rebuild all of the system on the fly, showing not only ways to do things, but also ways to solve problems and how to look at them to understand where the problem is!

  34. Is problem if i did it in 2D project instead of 3D project??

  35. Hey! Just wanted to say thanks for this! Excellent, clear instructions. Your approach to teaching is really natural – warm, exploration oriented, curious – and it's helped me feel welcomed to the Unity dev community (this is my first solo dev project). Thankstytytyty

  36. hey guys im new to unity how do i add the game scrren below the like 2d screen i only have the 2d screen

  37. I copied all of your steps exactly, however none of the drag events are ever called. Has Unity changed how you do this in a newer update since then?

  38. This video was very helpful. Thank you.

  39. I love your OCD. "I must make sure there is NO overlap!!!"

Leave a Reply

Your email address will not be published.