Drag and Drop System in Unity - Puzzle Game Example (PC and Mobile)

  Рет қаралды 53,720

GameDevel

GameDevel

4 жыл бұрын

Learn how the drag and drop mechanics work in unity! We will create a simple unity puzzle game for mobile or pc that will implement the mouse or touch drag and drop mechanics.
A lot of games especially for mobile use the drag and drop for puzzle games and it is a genre that is still raising and climbing the charts!
-- Drag and Drop System in Unity - Puzzle Game Example (PC and Mobile) --
📺 Watch v 2.0 of the Drag and Drop System with Inventory Example
• Drag and Drop System i...
Enjoy the video and smash the like and subscribe buttons!
SAVVU
Choose your Membership Level and get exclusive benefits from the Channel!
🥇 Support me on Patreon: / gamedevel
Or buy me a fine cup of coffee to boost my motivation (need caffeine!)
☕ www.buymeacoffee.com/SavvuGam...
Thank you :D
-----------------------------------------------------------------------------------------------------------
👋 Discord: / discord
🔔 Don't click here!: bit.ly/savvulink
💚 GooglePlay: bit.ly/SAVVUgamepage
💛 Itch.io: savvu-games.itch.io
🌐 Website: savvugames.com
💜 Instagram: / savvugames
💙 Facebook: / savvugames
🖤 Twitter: / savvugames
-----------------------------------------------------------------------------------------------------------
About Section:
Hey and welcome to my channel SAVVU Games!
I am just an indie game developer and I would love to have you on my gamedev journey and be there on yours as well.
On the channel you will find devlogs of my current game, unity tutorials and sometimes whatever I just want to share with you.
RIng the bell and join the Notificationsquad on Discord to win a shoutout on the next video by commenting with hashtag notificationsquad in the first 10 minutes of a new video! 🔔 (It's a lot of fun)
Make sure to Subscribe and don't miss your next GameDev Video.
Ciao :D
#savvu #draganddropunity #puzzlegame #unitypuzzlegame

Пікірлер: 196
@MOARMOARMAN
@MOARMOARMAN 4 жыл бұрын
Came from dani
@gamedevel22
@gamedevel22 4 жыл бұрын
That is really Epic! Hope you stay and drink your milk as well.
@MOARMOARMAN
@MOARMOARMAN 4 жыл бұрын
@@gamedevel22 MILK IS GREATEST
@Luluskuy
@Luluskuy Жыл бұрын
Heyy, thank you so much! This is the easiest drag and drop system that I have met in youtube! Gonna implement this on my game, good work! 😎
@priyajvora6060
@priyajvora6060 4 жыл бұрын
Honestly, this is absolutely fantastic! Thank you
@gamedevel22
@gamedevel22 4 жыл бұрын
Appreciate your nice words 😄
@jahanvi9429
@jahanvi9429 2 жыл бұрын
Thank you so much. This helped me so much
@robertmuller1881
@robertmuller1881 2 жыл бұрын
Excellent tutorial - thank you
@aj656666
@aj656666 4 жыл бұрын
Thank you for the video! It helped me at the right time!
@gamedevel22
@gamedevel22 4 жыл бұрын
Awesome glad you found me ! Thanks
@rakawiradarma9597
@rakawiradarma9597 2 жыл бұрын
Great tutorial, simple dan work. Thanks brother...
3 жыл бұрын
This is the best video I found on net, thx.
@gamedevel22
@gamedevel22 3 жыл бұрын
And I am sure you are the best viewer! Thx 😁
@ushio1511
@ushio1511 4 жыл бұрын
Thanks a lot! REALLY!! I'm starting in unity and this kind of puzzle had me stuck, you saved me! Greetings from Ecuador :)
@gamedevel22
@gamedevel22 4 жыл бұрын
This is why I love making Videos! Thank you very much and keep on learning 😁
@ushio1511
@ushio1511 4 жыл бұрын
​@@gamedevel22 I want to share with you the final game, thanks again for your tutorial. kzbin.info/www/bejne/amrZYmR5g9KhbLM (I'm working in a educational proyect, if you're interested, please contact to me)
@ajrmarchan
@ajrmarchan Жыл бұрын
Extremely helpfull video. Thank you.
@pedronecromosh
@pedronecromosh 3 жыл бұрын
helped me a lot! thanx
@gamedevel22
@gamedevel22 3 жыл бұрын
Thanks a lot for watching! :D
@musicvidquotes718
@musicvidquotes718 3 жыл бұрын
Thank you. Success for your channel. Gbu
@TheKr0ckeR
@TheKr0ckeR 2 жыл бұрын
Thanks for a great guide! I am creating a similar puzzle game. But objects are not same. One is a question, one is an answer. (question is: 15+5) answer is (20) so people should get the game object with question text on it, and drag & drop it in to answer. How would you approach that? In here, we are checking if object's are equal. But in my example, i cant do that.
@wadafakustudio934
@wadafakustudio934 3 жыл бұрын
It's So Great. Thanks
@gamedevel22
@gamedevel22 3 жыл бұрын
Thanks a lot!😀
@rathanhv4676
@rathanhv4676 4 жыл бұрын
Thank u so much sir
@karimmr8433
@karimmr8433 4 жыл бұрын
Thanks this what i need
@gamedevel22
@gamedevel22 4 жыл бұрын
Awesome nice to hear that😁
@theexplosive583
@theexplosive583 3 жыл бұрын
Thanks a lot you are Great,Your lessons even understand other people.
@gamedevel22
@gamedevel22 3 жыл бұрын
Really glad it was helpful 😁
@theexplosive583
@theexplosive583 3 жыл бұрын
@@gamedevel22 Саn уоu recomended books for beginers for unity scripting? and how you learn Unity Scripting?
@gamedevel22
@gamedevel22 3 жыл бұрын
Well I started out with KZbin to be honest..nowadays here is almost every kind of tutorial about scripting and even specific features. Unity has a lot of useful Videos and documentations as well.
@animationsbelike
@animationsbelike 2 жыл бұрын
THank you! :D
@MsGromboy
@MsGromboy 2 жыл бұрын
Great job :)
@gamedevel22
@gamedevel22 2 жыл бұрын
thank you!
@ngjiayi2705
@ngjiayi2705 3 жыл бұрын
Thank you for such a amazing video! btw how can I check if my object can't don't snap at the correct form?
@gamedevel22
@gamedevel22 3 жыл бұрын
Thank you for watching and your kind words! At 9:30 in the OnMouseUp() function you can see the if-else statement. The else part takes place when you let go of the sword at the wrong shadow so in there you add whatever you want if the player made a wrong move!
@sofiejohari5028
@sofiejohari5028 2 жыл бұрын
thanks for the great tutorial. i have followed and double-checked my coding, but my swords won't move. can you suggest anything about this?
@johanalmansyah6140
@johanalmansyah6140 2 жыл бұрын
amazing technic..thank you I follow this method but don't know how to make reset button
@gamedevel22
@gamedevel22 2 жыл бұрын
Thank you so much! For a reset button you could just reload the same scnene. This would reset everything to the begining state.
@johanalmansyah6140
@johanalmansyah6140 2 жыл бұрын
@@gamedevel22 its okay, thanks
@johanalmansyah6140
@johanalmansyah6140 2 жыл бұрын
@@gamedevel22 but for AddPoints function even finish is true, it just still continue at OnMouseUp ()
@arthurlanapereira
@arthurlanapereira 2 жыл бұрын
I don´t know if you´re going to see this comment, but thank you a lot, you helped me out a lot, but could you help me? The win screen isn´t showing in the game, just in the scene camera do you have any idea how can I correct it?
@MattisDeveloper
@MattisDeveloper 3 жыл бұрын
Nice and easy tutorial! :D How to prevent score to ++ if you drag 1 image to correct pos and keep click that image. then you add score all time :D
@mousse4410
@mousse4410 Жыл бұрын
Probably not the best way to do but it was my solution
@markyx24
@markyx24 Жыл бұрын
is it possible to randomize the positions of the silhouettes?
@deepgames9091
@deepgames9091 2 жыл бұрын
If I say that there are 12 random shapes in every set of puzzle and then you have to do the drag and drop thing on them what is the solution for that type of problem. And also if we we have a clock image up on the top of our screen and we have circle shape on the buttom of our screen and you have a slot between them and if you have drag that circle shape onto that slot to identify if the clock shape is identical to the circle that has been drag and drop what is the best solution for that as well. Please Help as soon as possible.
@momozaki4453
@momozaki4453 2 жыл бұрын
7:32 After you display them, how can you swap between each other?
@nitindodeja8866
@nitindodeja8866 3 жыл бұрын
hi, i'm new to this but just one question.. when u calculated startPosX, u subtracted localPosition.X from mousePos.X, what does that localPosition.X mean ?
@SuperheroCoding
@SuperheroCoding 3 жыл бұрын
localPosition.x is the position of the object that the script is attached to.
@davidaquino7023
@davidaquino7023 2 жыл бұрын
Great tutorial! How would I load a new scene after all objects have been placed into their correct positions? Thanks!
@gamedevel22
@gamedevel22 2 жыл бұрын
You can change the code in the WinScript to do whatever you want. Inside of the if statement in the Update function call a new scene. Thanks for watching!
@davidaquino7023
@davidaquino7023 2 жыл бұрын
@@gamedevel22 Hey, I got it to work! Thanks for helping me out!
@gamedevel22
@gamedevel22 2 жыл бұрын
Glad it worked!
@Zyugo
@Zyugo 2 жыл бұрын
Alternately, you could use Vector2 at most parts since the z-axis is useless in 2D games.
@HakimMatnang
@HakimMatnang 3 жыл бұрын
Savvu, did you know how to set the object to be done first before can get to the next object. Such as, i create match game like you did but im using numbers, so i want the user solve the number 1 first before proceed with number 2 and so on. When the user try to solve other number they cant unless they have solve 1
@gamedevel22
@gamedevel22 3 жыл бұрын
This is a great idea for your game and I would like to talk more about this in order to find a solution! Feel free to join the Discord Server and text me
@Learn2b
@Learn2b 4 жыл бұрын
Thanx alot for vedio . error with " ScreenToWorIdPoint " 'Camera' does not contain a definition for 'ScreenToWorIdPoint' and no accessible extension method 'ScreenToWorIdPoint' accepting a first argument of type 'Camera' could be found (are you missing a using directive or an assembly reference?) how can fix it ?
@gamedevel22
@gamedevel22 4 жыл бұрын
Are you sure you are using it like this: Camera.main.ScreenToWorldPoint also make sure that your main camera has the tag "MainCamera" that is also the default tag for the first camera in the scene! Let me know if this fixed the problem :D
@Learn2b
@Learn2b 4 жыл бұрын
@@gamedevel22 Thanx alot it's work
@shinesee
@shinesee 2 жыл бұрын
Thanks for the tutorial. I did exactly what you did. But when I click on a locked object again, it continues to add points. I have 3 objects in my scene. When 3 of them are locked, the game should be over. But after I lock 1 of them, if I click on it 2 times, it ends the game as it continues to add points. How can I fix this situation?
@yadwinderkaur
@yadwinderkaur 2 жыл бұрын
Thanks for this great tutorial. I have exactly followed the video but still, my sprites disappear just by clicking. They do not stay on until I drag them to their respective silhouette. Any suggestion on this issue?
@gamedevel22
@gamedevel22 2 жыл бұрын
Thank you very much! This is mainly caused because the object is transported somewhere else rather than under the mouse coursor. Check if you are using transform.position and transform.localPosiiton the right way.
@yadwinderkaur
@yadwinderkaur 2 жыл бұрын
@@gamedevel22 thank you very much for your response. I have another question: if I want to make one slot for at least two objects to be drawn. For example, making one silhouette for only 2objects which can be dragged. How can this be done? Thank you again in advance.
@ronin6158
@ronin6158 3 жыл бұрын
can you use onmousedrag ?
@temirmemir1891
@temirmemir1891 3 жыл бұрын
Hi! Thank you for the tutor, unforunately i have a problem. My pieces arent moving at all. How can I fix it?
@gamedevel22
@gamedevel22 3 жыл бұрын
Hey thanks a lot! Are you sure you have the colliders attched and checked the Script for mistakes?
@corbywhite4662
@corbywhite4662 3 жыл бұрын
@@gamedevel22 Thank you Savvu! I ve done all the proccess, i have the colliders on, the obects can be moved, but they just return to where they were. They dont snap onto SwordsBlack. why is that? Do i have to change all localPositions to Position? I only did the changes at the exact places you did
@gamedevel22
@gamedevel22 3 жыл бұрын
Have you checked if you use Position and localPosition the right way? The Problem may be because of that. Let me know if it worked
@subarnapokharel2218
@subarnapokharel2218 2 жыл бұрын
Can anyone pls provide whole code of the above tutorial?
@siomai7199
@siomai7199 3 жыл бұрын
Does GetMouseButtonDown works on Android too?
@paulgaida4165
@paulgaida4165 Жыл бұрын
How correctForm variable gets set? can't figure it out, getting correctForm has not been assigned...
@warfarecreations379
@warfarecreations379 4 жыл бұрын
I just love u
@gamedevel22
@gamedevel22 4 жыл бұрын
Hehe thanks I guess!
@ekmalhakimi2652
@ekmalhakimi2652 3 жыл бұрын
I'm cannot drag into the correct box how to fix it
@cesurcan1216
@cesurcan1216 4 жыл бұрын
so now i have another question. At the end, instead of text i want to make a button to appear which i scripted loads next scene. I put my button in the PoinsHandler object but i want to create a pop-up styled windows consist of multiple button. At the end, only the button which is on top of Hierarchy line in PointsHandler shows up in the game? How can i make all assets appear in the PointsHandler?
@gamedevel22
@gamedevel22 4 жыл бұрын
You could create the whole thing and make a prefab out of it. Then put the prefab as a public gameobject in the Script and instantiate it whenever you want!
@cesurcan1216
@cesurcan1216 4 жыл бұрын
@@gamedevel22 Thanks!
@cesurcan1216
@cesurcan1216 4 жыл бұрын
@@gamedevel22 so i made a game object, how can i implement that on the win script? Now it only gets first object in PointsHandler. I created a gameobject like points handler and changed the name in the script to my new gameobject. Any solutions?
@user-vj3yi4if4u
@user-vj3yi4if4u 3 жыл бұрын
thank you so much, but I have this error appear : error CS1061: 'GameObject' does not contain a definition for 'localPosition' and no accessible extension method 'localPosition' accepting a first argument of type 'GameObject' could be found (are you missing a using directive or an assembly reference?)
@gamedevel22
@gamedevel22 3 жыл бұрын
Make sure to check the upper case and lower case Letters. It should work
@user-vj3yi4if4u
@user-vj3yi4if4u 3 жыл бұрын
@@gamedevel22 The problem is that the error has disappeared, but it does not do anything. I attached the code to this link. Is it possible to see it and tell me what is the problem? . . pastebin.pl/view/4f1a36df . . Thank you
@o9o7_
@o9o7_ 2 жыл бұрын
can this be done in 3d?
@eldonedigo7942
@eldonedigo7942 2 жыл бұрын
Where was mousePosition declared because the cord is giving me an error Input does not contain a definition for mousePosition
@PainHidden1996
@PainHidden1996 4 жыл бұрын
this is amazing thank you so much, i just have one problem and it's that my objects keep going backk to their position even after putting them in their right place :( i did all the things you did but no lu
@gamedevel22
@gamedevel22 4 жыл бұрын
Are you sure you have all the triggers and tags right?
@wilmerandrecruzado1136
@wilmerandrecruzado1136 4 жыл бұрын
I don't know if you already solve your problem, but for the sake of newcomers, this is the code that works: (I declared the potion and potionBlack as GameObject first. Potion is the shape of my sprite not sword. potionBlack is the black part.) private void OnMouseUp(){ isBeingHeld = false; float Distance = Vector3.Distance(potion.transform.position,potionBlack.transform.position); if(Distance < 1){ potion.transform.position = potionBlack.transform.position; } else { potion.transform.position = resetPosition; } }
@manojkoti6052
@manojkoti6052 3 жыл бұрын
Hi, is it possible to match things when they collide and if it is possible can u make a tutorial on it?
@gamedevel22
@gamedevel22 3 жыл бұрын
Hey! How do you want the objects to collide?
@manojkoti6052
@manojkoti6052 3 жыл бұрын
@@gamedevel22 One of the objects have velocity and when it collides the other object of same type it should match it
@gamedevel22
@gamedevel22 3 жыл бұрын
You can have a collider on both objects with Trigger enabled and write a Script with a on OnTriggerEnter function. In there you can handle the Collision results
@franciscoalcantara4959
@franciscoalcantara4959 4 жыл бұрын
Everything works perfect but the swords move too slow and separate to the mouse. Something with the canvas settings o scale i guess? Thank you!
@gamedevel22
@gamedevel22 4 жыл бұрын
Are you sure you are using the Update function and not some LateUpdate?
@ryana.9821
@ryana.9821 4 жыл бұрын
i had a similar situation, maybe try using this: transform.position = Input.mousePosition
@elderrale
@elderrale 4 жыл бұрын
@@gamedevel22 i have the same problem... the object lags behind the mouse
@waseemali9900
@waseemali9900 3 жыл бұрын
How to reset all game objects position on click event?
@gamedevel22
@gamedevel22 3 жыл бұрын
You can have a public function in the same script as in the tutorial where you copy paste the part of the if else statement for the position reset option. Then you call this function for each object wherever you want 😎
@jshuen_
@jshuen_ Жыл бұрын
why my object can’t snap to the drop place
@khalidasofea9200
@khalidasofea9200 4 жыл бұрын
Hye, I havesome problems. Why my object all positioned at the center when play and how to adjust mouse speed? Thank you!
@yigitcam1696
@yigitcam1696 3 жыл бұрын
i got the same issue !! have u got any solutions ?
@aitormendia1043
@aitormendia1043 3 жыл бұрын
if you are in 3d, the solution maight be putting the Camera on Orthografic
@fadlanrazak1480
@fadlanrazak1480 3 жыл бұрын
hi, I got problem, when I click the object to drag, the object position changed... do you know how to fix this? thank you
@anouk6869
@anouk6869 3 жыл бұрын
I have the same problem
@gamedevel22
@gamedevel22 3 жыл бұрын
Have you tried using localposition when moving the sprites?
@fatemehzare2063
@fatemehzare2063 3 жыл бұрын
Hi, I have a problem in the first part. when I want to drag my object it moves really slow. what did I do wrong? It'll be nice of you to help me here. thanks a bunch!
@LastGamerName
@LastGamerName 3 жыл бұрын
Does it just move really slowly with the cursor? Or does the cursor seem to have a faster speed than the image?
@musicplacebo
@musicplacebo Жыл бұрын
@@LastGamerName cursor is faster
@legendtypgaming5080
@legendtypgaming5080 Жыл бұрын
Can you please help me after i finish to match all the objects the game stopped it says " Transform child out of bounds"
@nadaalfarraj5980
@nadaalfarraj5980 3 жыл бұрын
Can I use this script with UI image, then add my desired sprite to that image? I actually couldn't add sprite to my background as you present at the start of the video !! I dragged the sprite as you did but it came behind the background
@gamedevel22
@gamedevel22 3 жыл бұрын
I think this should work with ui images as well. You can also try to adjust the sorting order of your canvas and sprites
@nadaalfarraj5980
@nadaalfarraj5980 3 жыл бұрын
@@gamedevel22 what do you mean by adjusting my canvas?
@gamedevel22
@gamedevel22 3 жыл бұрын
Each object can be on a sorting layer and the whole canvas as well. You can find it in the inspector. Maybe this is the Problem why you cant see some sprites. Try to first implement the Script from the video with UI images.
@nadaalfarraj5980
@nadaalfarraj5980 3 жыл бұрын
@@gamedevel22 thank you soo much, I appreciate that
@antrung1371
@antrung1371 3 жыл бұрын
Could you help me with this? At 4:32, I couldn't find "Correct Form" box. Seem like it is missing from my Unity version. I'm using 2019.4.11f1. Please help me with this. Thank you.
@gamedevel22
@gamedevel22 3 жыл бұрын
The correct form is just a public Gameobject variable I have assigned to the script in order to place there the the correct black version of the sword
@antrung1371
@antrung1371 3 жыл бұрын
@@gamedevel22 Thank for your reply. I got a error name Error CS0116: a name space can't not directly contain members such as field or methors.... Do you know how to fix that. Thank you
@antrung1371
@antrung1371 3 жыл бұрын
Would you have time to take a look at my code here: drive.google.com/file/d/1-ZZDbYolsnPVFCZekLaeLnbbngQFykKQ/view?usp=sharing . Thank you a lot for it
@laurasavaglia8955
@laurasavaglia8955 3 жыл бұрын
@@antrung1371 not sure if youve already resolved this or not, but the issue is that correct form isnt a unity method, its just what he named his game object at the very start. for example, i named mine public gameobject ingredient; so, whatever u named ur game object right at the beginning/top of the file, use that not "correct form"
@aziemhisham2930
@aziemhisham2930 Жыл бұрын
I'm stuck at moving the object. I don't know why. Maybe because I use picture as an object.
@cesurcan1216
@cesurcan1216 4 жыл бұрын
Hi, i get this error, The type or namespace name 'Gameobject' could not be found (are you missing a using directive or an assembly reference?) Any solutions? Thanks
@cesurcan1216
@cesurcan1216 4 жыл бұрын
Solved it. Beacuse of a syntax error. But i have 2 new ones lol. Assets/Scripts/Move_System.cs(36,30): error CS0117: 'Input' does not contain a definition for 'mouseposition' Assets/Scripts/Move_System.cs(24,55): error CS0103: The name 'mousePos' does not exist in the current context
@cesurcan1216
@cesurcan1216 4 жыл бұрын
Solved them all LOL love you thx
@LKonstantina915
@LKonstantina915 3 жыл бұрын
if i want to make it for a 3D game, I just create a startPosZ then I do: startPosZ = mousePos.z - this.transform.localPosition.z and this.gameObject.transform.localPosition = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY, mousePos.z - startPosZ) ?
@gamedevel22
@gamedevel22 3 жыл бұрын
I haven't tried this in 3D but I guess you need to have that z direction and use always Vector3. If you have tested the above Script please let me know if it worked!
@LKonstantina915
@LKonstantina915 3 жыл бұрын
@@gamedevel22 well yours didnt work because I had some other script that used the camera, so I kinda made my own lol Thanks tho ^^
@waldanrazip1224
@waldanrazip1224 3 жыл бұрын
i already follow everything but it doesn't work. Object can't snap into the black places...
@nazirajsmn4280
@nazirajsmn4280 4 жыл бұрын
I have a problem. I dont know why my swords wont drop to the swordsBlack. I recheck everything's fine. my coding is same as yours. I dont know where is my mistake. I hope you can help.
@gamedevel22
@gamedevel22 4 жыл бұрын
Have you checked that you have correctly assigned everything in the inspector? Maybe you are not using the localPositions
@DonzDelongeJr
@DonzDelongeJr 4 жыл бұрын
@@gamedevel22 where localPosition placed ? I used Unity 2019.1.10f1 ,Thanks.
@krgamesstudio5476
@krgamesstudio5476 3 жыл бұрын
I have the same
@gamedevel22
@gamedevel22 3 жыл бұрын
Feel free to send the code of yours in our Discord Server and myself with other Developers can have a look
@youneskasdi
@youneskasdi 3 жыл бұрын
Amazing tut but i just couldn't get over the fact that you couldn't say "sword" correctly even after hearing it lol
@gamedevel22
@gamedevel22 3 жыл бұрын
Hahaha that's why I use slimes for the new drag and drop video 😂
@matheusscarpim5167
@matheusscarpim5167 3 жыл бұрын
hello could you give me the script? because mine is giving problems with bad arguments
@1234yokee
@1234yokee 3 жыл бұрын
Thank you so much sir. Really helpful. But please help me one thing.. How to prevent score to ++ if you drag 1 image to correct pos and keep click that image. then you add score all time.. How?? please help sir.. really thank u
@gamedevel22
@gamedevel22 3 жыл бұрын
Thanks for liking the video! You can disable the colliders and triggers of the object you placed in the correct position. That way you won't be able to interact with it.
@1234yokee
@1234yokee 3 жыл бұрын
@@gamedevel22 Thank again...It work .i really appreciate it
@shinesee
@shinesee 2 жыл бұрын
Hi. I'm having the same problem. How can I fix? Can you help me?
@falcorusticoluss
@falcorusticoluss 2 жыл бұрын
@@gamedevel22 thanks! had the same problem. u helped me too) if anyone needs it, add to private void OnMouseUp(): this.gameObject.GetComponent().enabled=false;
@espacepublicnumeriquepontl5461
@espacepublicnumeriquepontl5461 Жыл бұрын
@@falcorusticoluss thanks a lot for this ! Really ❤
@tunnelbear5265
@tunnelbear5265 3 жыл бұрын
I am using UI Image instead and have loaded the sprite into UI image as the sprite on its own was not coming to the front. Everything else is the same. But nothing is moving? Any way to fix this? Thanks
@tunnelbear5265
@tunnelbear5265 3 жыл бұрын
I think it's something to do with boxcollider2d as when I first add it the size is 1,1 in the middle of the UI image I then resize to correct size on all UI images but still doesn't move. Any fix for this? Thanks
@tunnelbear5265
@tunnelbear5265 3 жыл бұрын
@Savvu the GameDevel
@TranouEducation
@TranouEducation 4 жыл бұрын
It was amazing...and sooo easy.But I have a problem. MyScript is working. Everything is Ok but nothing is moving. I put my Sprite images into myScene ...but nothing... what am I doing wrong?
@gamedevel22
@gamedevel22 4 жыл бұрын
What exactly do you mean by nothing is moving? Maybe you havent assigned the colliders with is Trigger correctly?
@tiaraluna33
@tiaraluna33 3 жыл бұрын
@@gamedevel22 I have the same problem, it just moves very slightly
@tiaraluna33
@tiaraluna33 3 жыл бұрын
//mousePos = Camera.main.ScreenToWorldPoint(mousePos); I turned this off and then it worked
@TranouEducation
@TranouEducation 3 жыл бұрын
@@tiaraluna33 thanx a lot ☺️
@lakshayjain807
@lakshayjain807 2 жыл бұрын
where can i find source code ?
@Benjihalk
@Benjihalk 3 жыл бұрын
my man from germany
@gamedevel22
@gamedevel22 3 жыл бұрын
Haha you think so?
@Benjihalk
@Benjihalk 3 жыл бұрын
@@gamedevel22 when you searched for pronounciation there were some words in german
@gamedevel22
@gamedevel22 3 жыл бұрын
hehe great observation bro! True I grew up in Germany but I life in Greece currently
@Benjihalk
@Benjihalk 3 жыл бұрын
​@@gamedevel22 What would I need to add to the code if I wanted to do this with 2 different sprites? So that the silhouette you use in this video is like another sprite?
@gamedevel22
@gamedevel22 3 жыл бұрын
I don't really get that..In order to have other images just replace the Sprite
@user-tw9ck1qs5e
@user-tw9ck1qs5e 2 ай бұрын
why my item still can't move ?
@yanz3e14
@yanz3e14 3 жыл бұрын
hello..i followed this step by step but my object will not snap to its correct form..it will always return to its localposition..why is that?
@yanz3e14
@yanz3e14 3 жыл бұрын
this is the code.. using System.Collections; using System.Collections.Generic; using UnityEngine; public class MoveSystem : MonoBehaviour { public GameObject correctForm; private bool moving; private bool finish; private float StartPosX; private float StartPosY; private Vector3 resetPosition; // Start is called before the first frame update void Start() { resetPosition = this.transform.localPosition; } // Update is called once per frame void Update() { if(finish == false) { if (moving) { Vector3 mousePos; mousePos = Input.mousePosition; mousePos = Camera.main.ScreenToWorldPoint(mousePos); this.gameObject.transform.localPosition = new Vector3(mousePos.x - StartPosX, mousePos.y - StartPosY, this.gameObject.transform.localPosition.z); } } } private void OnMouseDown() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos; mousePos = Input.mousePosition; mousePos = Camera.main.ScreenToWorldPoint(mousePos); StartPosX = mousePos.x - this.transform.localPosition.x; StartPosY = mousePos.y - this.transform.localPosition.y; moving = true; } } private void OnMouseUp() { moving = false; if (Mathf.Abs(this.transform.localPosition.x - correctForm.transform.localPosition.x)
@gamedevel22
@gamedevel22 3 жыл бұрын
Make sure to Double check the Script and try to reduce the 1f value where you check for the Mathf.Abs. This will make it more sensitive
@yanz3e14
@yanz3e14 3 жыл бұрын
@@gamedevel22 hi thankyou for replying..i have double check the code and i dont see any difference..however i learn new problem..whenever i drag my image to its correctForm, it will return the image into its localposition..however, whenever i click on the image..the image will be placed directly in their assigned correctforms..it seems the code works for click not dragging.. and i can click the image again and the image will return to its localposition
@yanz3e14
@yanz3e14 3 жыл бұрын
i am using Unity 2019.2.9f1
@DonzDelongeJr
@DonzDelongeJr 4 жыл бұрын
Why mine can't moving the object ? Please solve this problem
@gamedevel22
@gamedevel22 4 жыл бұрын
Are the swords not following the mouse?
@DonzDelongeJr
@DonzDelongeJr 4 жыл бұрын
@@gamedevel22 Yes, the object is stuck and can't move
@gamedevel22
@gamedevel22 4 жыл бұрын
I am sure you missed some step of the tutorial! Is your Script and the swords gameobjects correctly with all the components?
@DonzDelongeJr
@DonzDelongeJr 4 жыл бұрын
@@gamedevel22 I follow step by step with other objects but still same errors
@conkerchip
@conkerchip 4 жыл бұрын
​@@DonzDelongeJr Not sure if you solved this, but if you didn't, on my version of Unity it sometimes does not recognise that a Box Collider 2D has been assigned to that object, so maybe check to see if it had been properly assigned.
@axilkhan4575
@axilkhan4575 4 жыл бұрын
my sword are not going back to the start positions i copy your each and every step please help
@gamedevel22
@gamedevel22 4 жыл бұрын
Are they staying on top of the shadows?
@axilkhan4575
@axilkhan4575 4 жыл бұрын
@@gamedevel22 no they are not staying at the shadow
@axilkhan4575
@axilkhan4575 4 жыл бұрын
@@gamedevel22 first of all i am very thankful to you as you replied ans the prob is if they are stay on shadow it not be perfectly stay at it and the second problem is if i click anywhere at the centre it will not move untill i grab it from very corners or sides !
@gamedevel22
@gamedevel22 4 жыл бұрын
Well if you want we can talk about it in our Discord Server and you can show me some s Screenshots of course! The link to join is in the description 😀
@axilkhan4575
@axilkhan4575 4 жыл бұрын
@@gamedevel22 ok graet i will join you there!
@followthescience5571
@followthescience5571 3 жыл бұрын
SAWD Unexpected laugh.
@gamedevel22
@gamedevel22 3 жыл бұрын
Haha thanks for the laugh 😂 I uploaded a new drag & drop video today..have a look it may help you
@karimmr8433
@karimmr8433 4 жыл бұрын
thanks sir so much , can put the code source
@gamedevel22
@gamedevel22 4 жыл бұрын
Thank you too! I am thinking of having all codes on github but not yet.
@anouk6869
@anouk6869 3 жыл бұрын
My swords will only stick in the right place when I place it next to the right place, not direct on. Somebody knows how to fix this?
@LastGamerName
@LastGamerName 3 жыл бұрын
If it's only working next to it in one direction, I would ask if you used "Mathf.Abs" so that it checks both directions of the axis. If it works in either direction, I would say to check the distance comparison and make sure one of the greater/less than symbols didn't get switched around or something like that? Hopefully that helps :)
@anouk6869
@anouk6869 3 жыл бұрын
@@LastGamerName Yeah I already fixed it. I had a typo which made it bug. 😬
@LastGamerName
@LastGamerName 3 жыл бұрын
@@anouk6869 Nice!
@DonHart
@DonHart 3 жыл бұрын
I need this code to compare with mine... Something is not working, It doesnt stay in the black shape, just return to its original position
@LastGamerName
@LastGamerName 3 жыл бұрын
There could a few reasons for this that I can think of without seeing your work :) 1: Did you attach the Correct Sword images to the script like at 4:35? 2: Is your drop threshold too small where you have to drop the image pixel perfect? 3: After checking that dragged image is on correct slot, did you change it's position to the local position of the correct slot? Personally I think it will probably be the first one. I'm always forgetting to drop my objects in.
@DonHart
@DonHart 3 жыл бұрын
@@LastGamerName ThnX, I re-wrote the code, and it worked, I'm still trying to figure it out where I made the mistake. ThanXXXX
@gamedevel22
@gamedevel22 3 жыл бұрын
The most common mistake is a typo somewhere in the code 😐
@DonHart
@DonHart 3 жыл бұрын
@@gamedevel22 I'm just learning, but dude, guys like you make a lot for people like me! I really appreciate it
@ryana.9821
@ryana.9821 4 жыл бұрын
swordddd
@gamedevel22
@gamedevel22 4 жыл бұрын
⚔️⚔️⚔️
@ibrahemslman8159
@ibrahemslman8159 2 жыл бұрын
💋
@charlesferry9465
@charlesferry9465 3 жыл бұрын
Code please lazy😅
@arabiannights7183
@arabiannights7183 3 жыл бұрын
Your script is too small to see. You should have zoomed in. Dislike...
@gamedevel22
@gamedevel22 3 жыл бұрын
Sry to see that you are facing problems with the Script!
@kozavr
@kozavr 2 жыл бұрын
I didn't like it. You are not explaining "Drag and Drop System in Unity", you are just saying "now we do this, and now we do that". It's one of those videos where you just show how something can be done. Doesn't mean you teach.
@Bpado93
@Bpado93 Жыл бұрын
Guys if your object not snap to its correct form you must be change this sentence (localPosition) in private void OnMouseUp() correctForm.transform.LocalPosition.x to correctForm.transform.position.x correctForm.transform.LocalPosition.y to correctForm.transform.position.y .... if (Mathf.Abs(this.transform.localPosition.x - correctForm.transform.position.x)
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4 МЛН
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 20 МЛН
Clown takes blame for missing candy 🍬🤣 #shorts
00:49
Yoeslan
Рет қаралды 46 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 25 МЛН
WORLD'S SHORTEST WOMAN
00:58
Stokes Twins
Рет қаралды 108 МЛН
Can AI Code Minecraft? Watch ChatGPT Try
8:06
BadGameDev
Рет қаралды 1,2 МЛН
Drag and drop in Unity UI - create your own inventory UI!
12:47
Coco Code
Рет қаралды 100 М.
How to make a drag and drop game in Unity
19:29
Tarodev
Рет қаралды 49 М.
How I made an Excellent Platformer
8:25
GoldenEvolution
Рет қаралды 266 М.
Simple Drag And Drop System | Unity 3D Tutorial For Beginners
6:47
User1 Productions
Рет қаралды 2,7 М.
Интерфейс для любого разрешения! Адаптивный UI в Unity
10:52
Мотай на ус • Школа разработки игр
Рет қаралды 49 М.
How to Make a Good 2D Camera
11:38
Game Maker's Toolkit
Рет қаралды 394 М.
Drag and Drop for Mobile & Desktop in Unity
6:54
Dev Leonardo
Рет қаралды 34 М.
Unity Drag and Drop Script | (Unity 3D tutorial)
12:40
The Best FREE Software for Game Development! (In my Opinion)
11:06
Ouch.. 🤕
00:30
Celine & Michiel
Рет қаралды 20 МЛН