Drag and Drop with New Input system! ( Touch and Mouse )
HTML-код
- Опубликовано: 18 июн 2024
- Download the code from here gist.github.com/Mohammad9760/...
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
THANK YOU!! Helped me out sooooo much!
Very good tutorial, thank you!
Very helpful and clear video
thank you very much :))
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?
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
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
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)
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.
@@GameDevGeeks Don't we need to unsubscribe using -= in an OnDisable method?
@@Mehrdad995GTa it's generally a good practice to help GC but unless you want to destroy the object unsubscribing would'nt do much.
@@GameDevGeeks Thanks for your help.🙏
When i drag this object and want to drag another, how can i do to get rid of the first object?
Hi👋 if both objects have colliders and the drag&drop script set up on them it should work with both of them.
If you have any questions ask them here :)
how to Drag the object fast and throw it far away ?
@@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
Have you got a version for 2D without physics?
Why does the drag method return Ienumerator?
@@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 :)
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 ?
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)
thanks a lot @@GameDevGeeks
@@sameralkhalili6554 glad I can help