Super Easy DRAG and DROP Unity Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 เม.ย. 2022
  • 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?
    Buy me a coffee ☕: ko-fi.com/bmoli
    ➤SUBSCRIBE to inflate my ego with a bigger number 💖
    ➤LIKE the video to help the algorithm or I'll drag & drop you
    ➤Join our DISCORD SERVER and be best friends: / discord
    Thanks for watching!
    #unity #tutorial #bmo

ความคิดเห็น • 48

  • @i_am_set
    @i_am_set 2 ปีที่แล้ว +26

    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

  • @benjaminchristl5283
    @benjaminchristl5283 2 ปีที่แล้ว +1

    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 👍

  • @stashatstake
    @stashatstake ปีที่แล้ว +3

    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

  • @stefansigurdsson2146
    @stefansigurdsson2146 2 ปีที่แล้ว

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

  • @ripdoxyyy
    @ripdoxyyy 2 ปีที่แล้ว

    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.

  • @noopsink_piano
    @noopsink_piano ปีที่แล้ว

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

  • @dailycompute
    @dailycompute 11 หลายเดือนก่อน

    Absolutely perfect! Thank you!

  • @ivandamyanov
    @ivandamyanov ปีที่แล้ว +4

    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!

  • @joshstephenson9711
    @joshstephenson9711 ปีที่แล้ว

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

  • @vapoman4034
    @vapoman4034 2 ปีที่แล้ว +1

    Thanks for this tutorial : Simple, clear and well explain. , that's why I already subscribe !

  • @SelaMalka
    @SelaMalka ปีที่แล้ว

    Super helpful video as usual, thank you!

  • @lukamuller7305
    @lukamuller7305 ปีที่แล้ว

    Amazing Tutorial Thanks !

  • @manumap782
    @manumap782 2 ปีที่แล้ว

    Big thank you!!

  • @hirejeffwu
    @hirejeffwu 7 หลายเดือนก่อน

    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".

  • @CodeLaniakea-tf5no
    @CodeLaniakea-tf5no 8 หลายเดือนก่อน

    Thank You! You save my time!

  • @beamlaku
    @beamlaku ปีที่แล้ว

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

  • @pt3012
    @pt3012 2 ปีที่แล้ว +1

    Ok, that last part with the subscribe was really funny! :D But I already did, so you should add an ELSE method for such cases too.

  • @mandamoon9149
    @mandamoon9149 2 ปีที่แล้ว +2

    Dropping on comment here for this scrumptious tutorial 🤤

  • @KaranDas69
    @KaranDas69 ปีที่แล้ว

    Thanks ♥️

  • @electricshade1861
    @electricshade1861 2 ปีที่แล้ว +3

    Nice

  • @Stompin40
    @Stompin40 2 ปีที่แล้ว +2

    Wow!

  • @LuizMoratelli
    @LuizMoratelli 2 ปีที่แล้ว +1

    Wow, I used something like this today, but I have a lot of issues using a Perspective Camera with 90 degrees of rotation in X axis and dragging an object inside a Parent with the same rotation of the camera. By the end I need to change the Camera to Ortographic and compensate the Y axis.

  • @cardario5323
    @cardario5323 2 ปีที่แล้ว

    omg finally someone made something without using UI

  • @squarepris1m203
    @squarepris1m203 6 หลายเดือนก่อน +1

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

  • @mosquito4504
    @mosquito4504 2 ปีที่แล้ว

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

  • @gabrieldj8191
    @gabrieldj8191 6 หลายเดือนก่อน

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

  • @evilmurlock
    @evilmurlock ปีที่แล้ว +2

    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.

  • @bossmanduty916
    @bossmanduty916 ปีที่แล้ว

    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

  • @TheZamphire
    @TheZamphire 2 ปีที่แล้ว

    I wonder im messing with a 3d platformer is there a way to stop physics from building up so an object does not slam down or bounce super high or carry momentum when you let go?

    • @pt3012
      @pt3012 2 ปีที่แล้ว +1

      I guess that's due to the rigidbody. Maybe you could set it to kinematic when the mouse is dragging and add an OnMouseUp additionally, where you set the kinematic to false again.
      docs.unity3d.com/ScriptReference/Rigidbody-isKinematic.html

    • @TheZamphire
      @TheZamphire 2 ปีที่แล้ว

      @@pt3012Thank you, ill try that in the morning

  • @user-cq6lx3vx9d
    @user-cq6lx3vx9d 5 หลายเดือนก่อน

    will it work if Rigidbody is added?!

  • @cardario5323
    @cardario5323 ปีที่แล้ว

    hey does this work in 3d too?

  • @TransGuyShane
    @TransGuyShane 2 ปีที่แล้ว +3

    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 :)

    • @max.playsgames
      @max.playsgames 2 ปีที่แล้ว +1

      not 100% sure, but maybe something like touchphase could work for that, although from memory even if you do mouse it still works for touch anyway but id say you can definitely find a way to use this for a tablet game with one of those options

    • @TransGuyShane
      @TransGuyShane 2 ปีที่แล้ว +1

      @@max.playsgames thank you :)
      I will look into that :)

  • @Sagardeep_Das
    @Sagardeep_Das 9 หลายเดือนก่อน

    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.

  • @Hassanali-jr4yb
    @Hassanali-jr4yb 9 หลายเดือนก่อน

    does this will work on mobile too ?

  • @NotASpyReally
    @NotASpyReally 2 ปีที่แล้ว

    This is great but it doesn't work well in 3D :(

  • @SmellGrow
    @SmellGrow 10 หลายเดือนก่อน

    It won’t work why is it going -20 in z

  • @user-rj4ef8dv9o
    @user-rj4ef8dv9o 5 หลายเดือนก่อน

    I spent several hours but couldn't do this whti Visual Scripting...omg!

  • @callmecrazy1337
    @callmecrazy1337 ปีที่แล้ว

    this -dosent- fucking work -please help-

    • @owen22s19
      @owen22s19 ปีที่แล้ว

      how did you get it to word

  • @XusermrX
    @XusermrX ปีที่แล้ว +3

    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 Camera.main.ScreenToWorldPoint(Input.mousePosition);
    }
    private void OnMouseDown()
    {
    //Capture the mouse offset
    mousePositionOffset = gameObject.transform.position - GetMouseWorldPosition();
    }
    private void OnMouseDrag()
    {
    transform.position = GetMouseWorldPosition() + mousePositionOffset;
    }
    }

    • @InanimateJR
      @InanimateJR ปีที่แล้ว +1

      ^^ This needs a pin