Unity Tutorial – Drag & Drop Tutorial #1 [RPGs, Card Games, uGUI]
quill18creates
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.
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]
16.12.2021
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?
Good tutorial but way too long!
I have a question: i al developing The cards con photoshop, how can i export them To unity? Or cannot do it?
Nice one … Superb For Beginners and easy understandable…
Thank you! Awesome work!
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)
{
Debug.Log("OnBeginDrag");
offset = transform.position – new Vector3(eventData.position.x, eventData.position.y, 0);
}
public void OnDrag(PointerEventData eventData)
{
Debug.Log("OnDrag");
transform.position = eventData.position + offset;
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log("OnEndDrag");
}
}
will this work for android touchpad as well?
Quill18, I remember that name. What did you do on YouTube a few years ago, was it league?
This is perfect just what Im looking for 😉 will this work on mobile devices as is (without the need to change the code)?
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);
}
i wish i had some money to pay people to do this for me this is going to take a awhile
Any idea of assembly simulation where you drag objects where they should be placed properly. somehow like pc assemble simulations.
12:54 did you say "embiggen", well it's a perfectly cromulent word.
does it work in unity 2017?
Is there a way to change the button pressed to drag?
Any advice on using this same script for 3D objects?
"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)
Can you help me with some things?
Still really useful, huge thank's !
Can I use it to drag and drop an object in android application?
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
太真实了 兄弟
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 !!
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.
Fantastic video. Love the pace and level of detail you go into. Liked and subscribed!
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.
Imbiggen it.
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.
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;
}
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?
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
thanks.
but how did you design that game UI you used at the beginning of this tutorial. please we need a video on that. thanks
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!
Amazing, thank you quill18
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
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.
What version of unity were you using when you made this?
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
Thanks! This was very helpful!
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.
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
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.
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!
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.
Greate video. Keep making these small errors :p they are quite educational
Old…
Thanks very much, even six years still usefull!
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?
Is there any way to drag just a floating copy of the card, and not the actual image?