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.
@@gamedevel22 I want to share with you the final game, thanks again for your tutorial. ua-cam.com/video/49v11CNmn6Q/v-deo.html (I'm working in a educational proyect, if you're interested, please contact to me)
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?
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 ?
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
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?
@@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
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?
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.
@@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.
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!
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.
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 ?
Well I started out with UA-cam 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.
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.
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 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
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
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
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) ?
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!
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?
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!
@@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?
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!
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
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.
@@gamedevel22 thanks! had the same problem. u helped me too) if anyone needs it, add to private void OnMouseUp(): this.gameObject.GetComponent().enabled=false;
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
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!
@@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?
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
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; }
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 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
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
@@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"
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 😎
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 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
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
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.
@@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.
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
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
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
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
@@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 !
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.
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 :)
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.
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)
Came from dani
That is really Epic! Hope you stay and drink your milk as well.
@@gamedevel22 MILK IS GREATEST
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.
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! 😎
Honestly, this is absolutely fantastic! Thank you
Appreciate your nice words 😄
Thanks a lot! REALLY!! I'm starting in unity and this kind of puzzle had me stuck, you saved me!
Greetings from Ecuador :)
This is why I love making Videos! Thank you very much and keep on learning 😁
@@gamedevel22 I want to share with you the final game, thanks again for your tutorial.
ua-cam.com/video/49v11CNmn6Q/v-deo.html
(I'm working in a educational proyect, if you're interested, please contact to me)
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?
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 ?
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
@@gamedevel22 Thanx alot it's work
Great tutorial, simple dan work. Thanks brother...
Thank you so much. This helped me so much
This is the best video I found on net, thx.
And I am sure you are the best viewer! Thx 😁
Excellent tutorial - thank you
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?
Extremely helpfull video. Thank you.
Thank you for the video! It helped me at the right time!
Awesome glad you found me ! Thanks
Hi! Thank you for the tutor, unforunately i have a problem. My pieces arent moving at all. How can I fix it?
Hey thanks a lot! Are you sure you have the colliders attched and checked the Script for mistakes?
@@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
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
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?
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.
@@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.
Great tutorial! How would I load a new scene after all objects have been placed into their correct positions? Thanks!
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!
@@gamedevel22 Hey, I got it to work! Thanks for helping me out!
Glad it worked!
Thank you. Success for your channel. Gbu
amazing technic..thank you
I follow this method but don't know how to make reset button
Thank you so much! For a reset button you could just reload the same scnene. This would reset everything to the begining state.
@@gamedevel22 its okay, thanks
@@gamedevel22 but for AddPoints function even finish is true, it just still continue at OnMouseUp ()
hi, I got problem, when I click the object to drag, the object position changed... do you know how to fix this? thank you
I have the same problem
Have you tried using localposition when moving the sprites?
helped me a lot! thanx
Thanks a lot for watching! :D
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.
How correctForm variable gets set? can't figure it out, getting correctForm has not been assigned...
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?
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!
Are you sure you are using the Update function and not some LateUpdate?
i had a similar situation, maybe try using this: transform.position = Input.mousePosition
@@gamedevel22 i have the same problem... the object lags behind the mouse
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 ?
localPosition.x is the position of the object that the script is attached to.
Thanks a lot you are Great,Your lessons even understand other people.
Really glad it was helpful 😁
@@gamedevel22 Саn уоu recomended books for beginers for unity scripting?
and how you learn Unity Scripting?
Well I started out with UA-cam 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.
Can anyone pls provide whole code of the above tutorial?
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.
Have you checked that you have correctly assigned everything in the inspector? Maybe you are not using the localPositions
@@gamedevel22 where localPosition placed ? I used Unity 2019.1.10f1 ,Thanks.
I have the same
Feel free to send the code of yours in our Discord Server and myself with other Developers can have a look
7:32 After you display them, how can you swap between each other?
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
Probably not the best way to do but it was my solution
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?)
Make sure to check the upper case and lower case Letters. It should work
@@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
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
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
Where was mousePosition declared because the cord is giving me an error
Input does not contain a definition for mousePosition
I'm stuck at moving the object. I don't know why. Maybe because I use picture as an object.
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) ?
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!
@@gamedevel22 well yours didnt work because I had some other script that used the camera, so I kinda made my own lol Thanks tho ^^
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?
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!
@@gamedevel22 Thanks!
@@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?
It's So Great. Thanks
Thanks a lot!😀
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!
Does it just move really slowly with the cursor? Or does the cursor seem to have a faster speed than the image?
@@LastGamerName cursor is faster
Great job :)
thank you!
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
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.
@@gamedevel22 Thank again...It work .i really appreciate it
Hi. I'm having the same problem. How can I fix? Can you help me?
@@gamedevel22 thanks! had the same problem. u helped me too) if anyone needs it, add to private void OnMouseUp(): this.gameObject.GetComponent().enabled=false;
@@falcorusticoluss thanks a lot for this ! Really ❤
Hye, I havesome problems. Why my object all positioned at the center when play and how to adjust mouse speed? Thank you!
i got the same issue !!
have u got any solutions ?
if you are in 3d, the solution maight be putting the Camera on Orthografic
i already follow everything but it doesn't work. Object can't snap into the black places...
Alternately, you could use Vector2 at most parts since the z-axis is useless in 2D games.
Hi, is it possible to match things when they collide and if it is possible can u make a tutorial on it?
Hey! How do you want the objects to collide?
@@gamedevel22
One of the objects have velocity and when it collides the other object of same type it should match it
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
Thank you for such a amazing video! btw how can I check if my object can't don't snap at the correct form?
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!
my man from germany
Haha you think so?
@@gamedevel22 when you searched for pronounciation there were some words in german
hehe great observation bro! True I grew up in Germany but I life in Greece currently
@@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?
I don't really get that..In order to have other images just replace the Sprite
is it possible to randomize the positions of the silhouettes?
why my object can’t snap to the drop place
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
Are you sure you have all the triggers and tags right?
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;
}
}
Can you please help me after i finish to match all the objects the game stopped it says " Transform child out of bounds"
Thanks this what i need
Awesome nice to hear that😁
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.
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
@@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
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
@@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"
THank you! :D
How to reset all game objects position on click event?
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 😎
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?
What exactly do you mean by nothing is moving? Maybe you havent assigned the colliders with is Trigger correctly?
@@gamedevel22 I have the same problem, it just moves very slightly
//mousePos = Camera.main.ScreenToWorldPoint(mousePos);
I turned this off and then it worked
@@tiaraluna33 thanx a lot ☺️
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?
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)
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
@@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
i am using Unity 2019.2.9f1
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
I think this should work with ui images as well. You can also try to adjust the sorting order of your canvas and sprites
@@gamedevel22 what do you mean by adjusting my canvas?
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.
@@gamedevel22 thank you soo much, I appreciate that
Why mine can't moving the object ? Please solve this problem
Are the swords not following the mouse?
@@gamedevel22 Yes, the object is stuck and can't move
I am sure you missed some step of the tutorial! Is your Script and the swords gameobjects correctly with all the components?
@@gamedevel22 I follow step by step with other objects but still same errors
@@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.
why my item still can't move ?
Does GetMouseButtonDown works on Android too?
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
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
@Savvu the GameDevel
Thank u so much sir
I'm cannot drag into the correct box how to fix it
Amazing tut but i just couldn't get over the fact that you couldn't say "sword" correctly even after hearing it lol
Hahaha that's why I use slimes for the new drag and drop video 😂
can you use onmousedrag ?
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
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
Solved them all LOL love you thx
hello could you give me the script? because mine is giving problems with bad arguments
my sword are not going back to the start positions i copy your each and every step please help
Are they staying on top of the shadows?
@@gamedevel22 no they are not staying at the shadow
@@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 !
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 😀
@@gamedevel22 ok graet i will join you there!
can this be done in 3d?
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
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.
@@LastGamerName ThnX, I re-wrote the code, and it worked, I'm still trying to figure it out where I made the mistake.
ThanXXXX
The most common mistake is a typo somewhere in the code 😐
@@gamedevel22 I'm just learning, but dude, guys like you make a lot for people like me!
I really appreciate it
where can i find source code ?
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?
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 :)
@@LastGamerName Yeah I already fixed it. I had a typo which made it bug. 😬
@@anouk6869 Nice!
thanks sir so much , can put the code source
Thank you too! I am thinking of having all codes on github but not yet.
I just love u
Hehe thanks I guess!
SAWD
Unexpected laugh.
Haha thanks for the laugh 😂
I uploaded a new drag & drop video today..have a look it may help you
Code please lazy😅
swordddd
⚔️⚔️⚔️
💋
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.
Your script is too small to see. You should have zoomed in. Dislike...
Sry to see that you are facing problems with the Script!
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)