Super Easy DRAG and DROP Unity Tutorial

preview_player
Показать описание
In practically 3 lines of code, learn how to add Drag and Drop mechanics into your game by allowing you to use your mouse to click on a GameObject, drag them to a new position, let go of the mouse button and their position will update.

✨Want to support the channel?

➤SUBSCRIBE to inflate my ego with a bigger number 💖

➤LIKE the video to help the algorithm or I'll drag & drop you

Thanks for watching!

#unity #tutorial #bmo
Рекомендации по теме
Комментарии
Автор

Bro! You’re scaring me with how accurate these tutorials are with my needs. Literally have “drag & drop” next on my todo list that I’m gonna do tomorrow! I’m happy to see I’ll have a trusted tutorial to follow for it. The timing is impeccable

i_am_set
Автор

Great tutorial, thank you! For anyone that wasn't able to get this to work, make sure your camera projection type is set to "Orthographic".

hirejeffwu
Автор

I was wondering why a super basic tutorial wouldn't work for me, I found out about Perspective and Ortographic cameras and how you need to use a Raycast instead if using the Perspective camera for this to work. Thanks for the video, it's down to the point!

ivandamyanov
Автор

Your short tutorials reignited my interest in making games. They are very helpful and short so it is always easy to find exactly the tutorials i need.

But I will watch all new videos regardless if i need them or not :D
Keep em coming 👍

benjaminchristl
Автор

Nice video, man. Kept it really concise, very important in game dev in my opinion. And the overall tone of the video was also light and refreshing

stashatstake
Автор

great tutorial, anyone know if theres a way you can make it so it cant go out of a specified area?

squareprism
Автор

Excellent editing, pacing, etc. All tutorial-makers can learn from this.

joshstephenson
Автор

Sir, your content is way too good. From your explanations to keeping the videos short yet informative, you may be the most helpful channel I've ever found.

ripdoxyyy
Автор

when you draged the subscribe from out of screen that was so funy I died.
Also thanks for the turorial, i tried some other interface for drag and droping, but I think that only worked with UI elements, so this was exactly what I needed.

evilmurlock
Автор

I love how concise these videos are, makes learning really easy and fun!

stefansigurdsson
Автор

Dropping on comment here for this scrumptious tutorial 🤤

mandamoon
Автор

Thank you so much for the quick and concise tutorial :D

noopsink_piano
Автор

Here is the code to copy and paste:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class draggable : MonoBehaviour
{
Vector3 mousePositionOffset;

private Vector3 GetMouseWorldPosition()
{
//capture mouse position & return WorldPoint
return
}

private void OnMouseDown()
{
//Capture the mouse offset
mousePositionOffset = gameObject.transform.position - GetMouseWorldPosition();
}
private void OnMouseDrag()
{
transform.position = GetMouseWorldPosition() + mousePositionOffset;
}
}

XusermrX
Автор

Add rigid body and box collider 2d for a pretty cool physics engine.

gabrieldj
Автор

how do you make it so that the drag and drop item doesn't go through the walls if you try drag it through the walls

bossmanduty
Автор

Help. After executing the code in script I can move my objects only vertically not all the way around background.
Edit - Problem Solved. I need to click on the blue box to drag anywhere. Thanks so much for this tutorial.

Sagardeep_Das
Автор

Does this work on buttons for mobile games? If not, is there a way to modify it so it does work for mobile?
I'm working on a game for my niece, this is perfect for my game but the game is going to be for her tablet, not a pc.
I suck at coding so sorry if this is super easy and I'm just being stupid but I'd love to know :)

TransGuyShane
Автор

Easy and helpful tutorial. plus creative and funny way to ask for subscribing. 👍👍

beamlaku
Автор

omg finally someone made something without using UI

cardario
Автор

Is there way to drag something using different button instead of mouse button? For example i want to drag my object by using "=" key

mosquito