ไม่สามารถเล่นวิดีโอนี้
ขออภัยในความไม่สะดวก

EASY Drag and Drop for UI - Unity Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2024
  • ➡️➡️➡️UNITY BLACK FRIDAY SALE ⬅️⬅️⬅️
    assetstore.uni...
    ⏱️ November 14 21:00 PT - December 4 23:59 PT ⏱️
    📥 Get the Source Code 📥
    / 58469035
    🤝 Support Me 🤝
    Patreon: / samyg
    Donate: ko-fi.com/samyam
    ►🔗 Relevant Video Links 🔗
    ᐅ(PREVIOUS VIDEO) Easy Drag and Drop with Input System 2D | 3D - Unity Tutorial
    • Easy Drag and Drop wit...
    ᐅRectTransformUtility.ScreenPointToWorldPointInRectangle Unity Documentation
    docs.unity3d.c...
    ᐅInterface IDragHandler Documentation: docs.unity3d.c...
    ►Assets shown in this video:
    ᐅGUI PRO Kit - Fantasy RPG:
    assetstore.uni...
    ᐅAlien Fantasy Forest: assetstore.uni...
    ᐅOdin - Inspector and Serializer: assetstore.uni...
    ᐅHQ FPS Weapons: assetstore.uni...
    ᐅDreamteck Splines: assetstore.uni...
    ᐅFirst person narrative adventures + complete puzzle engine: assetstore.uni...
    ᐅNature Renderer: Personal License: assetstore.uni...
    ᐅThe Vegetation Engine: assetstore.uni...
    ᐅExpanse - Volumetric Skies, Clouds, and Atmospheres in HDRP: assetstore.uni...
    ᐅFantastic City Generator: assetstore.uni...
    ᐅRPG Character Mecanim Animation Pack: assetstore.uni...
    ᐅPOLYGON Dungeon Realms - Low Poly 3D Art by Synty: assetstore.uni...
    ᐅAnimancer Pro: assetstore.uni...
    This video shows an easy built in way to drag and drop a UI object in Unity. You can also drag and drop a 2d collider and 3d collider object by adding the respective Physics Raycaster components to the camera, however the actual logic for correctly dragging and dropping a 3d object taking into account perspective is not covered in this video. For more information on that refer to my previous video ( • Easy Drag and Drop wit... ). We use the IDragHandler interface and implement it. We then convert our mouse position which is in screen coordinates to world coordinates with respect to the RectTransform.
    ►⏱️ Timestamps ⏱️
    0:00 Intro
    0:13 Sponsored Message
    0:43 Scene Setup
    1:51 Drag And Drop
    7:20 IBeginDrag or IEndHandler
    7:44 Physics Raycaster for Colliders
    8:41 Outro
    💖💖THANK YOU TO ALL MY PATRONS 💖💖
    ❯❯❯ My Links ❮❮❮
    💗 Patreon 💗
    / samyg
    💬 Discord Server 💬
    / discord
    🐦 Twitter 🐦
    / samyam_utube
    📚 Facebook 📚
    / samyam.youtube
    🎵 Music 🎵
    Ambient Gold
    streambeats.com
    👍 Like and Subscribe! 👍
    🖥️ Computer Setup 🖥️
    *As an Amazon Associate I earn from qualifying purchases.
    www.amazon.com...
    Disclosure: This post may contain affiliate links, which means we may receive a commission if you click a link and purchase something that we have recommended. While clicking these links won't cost you any money, they will help me fund my development projects while recommending great assets!
    #madewithunity #gamedev #unity

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

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

    ➡️➡️➡️UNITY BLACK FRIDAY SALE ⬅️⬅️⬅️
    assetstore.unity.com/?aid=1101ljAbS
    ⏱️ November 14 21:00 PT - December 4 23:59 PT ⏱️
    This post contains affiliate links which we may receive a small commission ♥️

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

    It's really good to see drag n drop on new input!

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

    Nice when they make it easy. I've used drag and drop a fair amount in the past.

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

    Coooooooool !! I've going to try this for creating a path on a map. I want a mini-map to come up (UI image of the map) then allow the player to drag a mouse or finger across it to create a path for something to follow. I bet this would work great for that.

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

    What an easy way to make such a complex system (worked on it a couple of times from scratch)
    The weirdest thing about it is that it recognized objects without them having any colliders.
    You never stop being awesome do ya?

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

      😄 Thank you!! Recognizes UI objects automatically, but needs extra steps (colliders + raycaster component on camera) for non UI objects

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

    Hey, could you make a video about 2D aiming with a mouse and a gamepad with the input system? I'm having issues with jittery aiming with my implementation. Thanks!

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

    @samyam Why do you need to transfer your screen coordinates to world coordinates if you are just moving something within the UI? It seems unnecessary for UI. Is this just copy+paste from the Unity docs, or do you understand this, and there is a good reason?

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

    Thank for your awesome video.
    For me on dragging, I was able to move UI outside the screen which was not expected.
    I added custom logic to detect globalMousePosition and checked it against screen size.
    Can you please do a video on anchor positions and how to convert one anchor position to another or to global etc

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

    Thank you! :)

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

    and how to keep element within the bounds of the canvas ?? any code example ?? thanks!

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

      For me on dragging, I was able to move UI outside the screen which was not expected. I added custom logic to detect globalMousePosition and checked it against screen size.
      Beware of Anchor Positioning

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

    Nice Tutorial. I have a Problem with the Endposition of the UI-Element. On end draging the Elemt is not under the Mouse. Know anyone the solution

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

    Thanks!

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

    The problem is: are you really using the new input system if you rely on these "old" interfaces? Can it work with custom input? Controller for example

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

      Technically yes you are using the new system, and the benefit is that you can then use the new system for all of the other input in your project. You can also make it work with controllers.

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

      @@samyam yes I researched a bit better how it works and you are right, basically any input you bind to UI/Click is valid to start a drag event, thanks for the answer

  • @deepakgiri.j1973
    @deepakgiri.j1973 2 ปีที่แล้ว +1

    I am waiting for your Next UE5 live stream

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

      Yes! I’ve just been really busy 😵‍💫

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

    Thank you for this tutorial. All this is fine as long as it's only the UI in the scene. Try to put this on a 3D game with a player where you use the new Input system for controls. Then the UI inputs simply do not work. No button presses etc. No one does a tutorial with a complex scene. If you can do these UI controls plus a simple 3D game and show how both the UI and the player controls work side but side in the same scene, you are a genius!

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

      You just need to create 2 different action maps, one for player (to move in the game) and one for UI.
      As soon as you need to switch to one or the other, you need to set the current schema accordingly.
      That way the new input system recognize what you are trying to do.

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

      @@alessandroricci8720 HAve you actually done this or are you saying what Unity and everybody else says cause in reality it doesn't work unless you use both input systems and also starts the scene without the player and then initiate the player by code. I tried using two action maps but the UI buttons DO NOT work. I can't share the project as it a is a release.

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

      @@diliupg I'm developing right now a 2d platformer and i'm using it. When the player open inventory, or access teminal, i'll just switch between the 2 action maps.
      And it's also work with gamepad.
      Was not easy to make it working, but is feasible.

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

    No matter how many tutorials I follow, these Drag Interfaces just don't work. Unity is such a mess. :(

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

      As a workaround you can do it manually
      th-cam.com/video/HfqRKy5oFDQ/w-d-xo.html
      I included a section on what you would do if you want to use it with UI

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

    Mam please make video enter and exit button for car for android phone in unreal engine 4

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

    👍😎

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

    1st