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

Drag and Drop with New Input system! ( Touch and Mouse )

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ส.ค. 2024
  • Download the code from here gist.github.co...
    in this video you'll learn how to use the new input system to drag and drop game objects by dragging the mouse or on touch screen. we setup the input action bindings on the component so you don't have to setup anything, you can just download the code and attach it on objects and you'll be able to drag and drop them.
    Subscribe / @triplequotes
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    How To Rotate Objects with New Input system • Rotate Objects with Ne...
    Unity Tutorial Playlist • Detect Double Clicks i...
    Unity VFX Tutorials • Realistic Muzzle Flash...
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    time stamps
    0:00 intro
    0:55 set up
    1:28 Input Actions
    3:15 get touch / mouse position
    4:35 check if clicked on
    7:25 drag
    10:00 add physics
    11:10 demo

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

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

    Very helpful and clear video
    thank you very much :))

  • @gfujigo
    @gfujigo 8 หลายเดือนก่อน

    THANK YOU!! Helped me out sooooo much!

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

    Very good tutorial, thank you!

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

    Can anyone help me?
    I want to adjust the settings of the game controls, it is for Android
    The settings are such that the party can move the fire button and customize it as he likes

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

    I like this method a lot. Is there a way to do this without having to put this script on your 'grabbable' objects? Also is there a reason you prefer to use properties instead of just calling the raycasts etc in your functions?

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

      Hi. there's definitely a way to do it without attaching a script to those objects but I found this to make sense and be more predictable.
      and yes when you do raycasts in a property the raycast runs only when you use the property instead of every frame if you do it in update for example and it's also cleaner like this I think, so that's why XD

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

    Can you write this code without using ternary operators? Im unsure why when you subscribe to the actions, like press.performed that you set it equal to _ , with a ternary operator afterwards, eg: press.performed += _ => (other code here)

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

      Hi Reid, performed is an event in InputAction objects and you can add method calls to an event (aka subscribing to it) and ( ) => is the syntax for anonymous functions but it you don't need any arguments passed to the anonymous function you can just put an _ there.
      so you can define a method and subscribe that to an event or you can subscribe an anonymous function to it.
      let me know if my explanation was not enough, cheers.

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

      @@GameDevGeeks Don't we need to unsubscribe using -= in an OnDisable method?

    • @GameDevGeeks
      @GameDevGeeks  11 หลายเดือนก่อน +1

      @@Mehrdad995GTa it's generally a good practice to help GC but unless you want to destroy the object unsubscribing would'nt do much.

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

      @@GameDevGeeks Thanks for your help.🙏

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

    If you have any questions ask them here :)

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

      how to Drag the object fast and throw it far away ?

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

      @@supersocial9002 you may want to get the direction of camera to the object and add it to the objects velocity when its released but depends on what youre looking for

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

      Have you got a version for 2D without physics?

    • @mrquokka4733
      @mrquokka4733 3 หลายเดือนก่อน

      Why does the drag method return Ienumerator?

    • @GameDevGeeks
      @GameDevGeeks  3 หลายเดือนก่อน

      @@mrquokka4733 that is a Coroutine aka an async function, which means that this method will not block the execution and can run while other stuff is happening. you could instead have conditions in the Update method which runs every frame, but doing it with a coroutine is more performant and the code ends up cleaner.
      you can search for coroutines in C# to learn more about it.
      cheers :)

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

    When i drag this object and want to drag another, how can i do to get rid of the first object?

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

      Hi👋 if both objects have colliders and the drag&drop script set up on them it should work with both of them.

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

    iam trying it in yellow head cap , which is on table , but it is fall down to floor ? , how can i back it to table again ?

    • @GameDevGeeks
      @GameDevGeeks  10 หลายเดือนก่อน +1

      you need to add colliders to all the objects that you don't want to go through eachother (if you add a MeshCollider make sure to make it convex)

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

      thanks a lot @@GameDevGeeks

    • @GameDevGeeks
      @GameDevGeeks  10 หลายเดือนก่อน +1

      @@sameralkhalili6554 glad I can help