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

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 พ.ย. 2024

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

  • @MOARMOARMAN
    @MOARMOARMAN 4 ปีที่แล้ว +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

  • @priyajvora6060
    @priyajvora6060 4 ปีที่แล้ว +4

    Honestly, this is absolutely fantastic! Thank you

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Appreciate your nice words 😄

  • @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! 😎

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

    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 ปีที่แล้ว +1

      This is why I love making Videos! Thank you very much and keep on learning 😁

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

      ​@@gamedevel22 I want to share with you the final game, thanks again for your tutorial.
      th-cam.com/video/49v11CNmn6Q/w-d-xo.html
      (I'm working in a educational proyect, if you're interested, please contact to me)

  •  4 ปีที่แล้ว +1

    This is the best video I found on net, thx.

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      And I am sure you are the best viewer! Thx 😁

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

    Thank you so much. This helped me so much

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

    Great tutorial, simple dan work. Thanks brother...

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

    Thank you for the video! It helped me at the right time!

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Awesome glad you found me ! Thanks

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

    Excellent tutorial - thank you

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

    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.

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

    Extremely helpfull video. Thank you.

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

    helped me a lot! thanx

    • @gamedevel22
      @gamedevel22  3 ปีที่แล้ว

      Thanks a lot for watching! :D

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

    Thanks a lot you are Great,Your lessons even understand other people.

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

      Really glad it was helpful 😁

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

      @@gamedevel22 Саn уоu recomended books for beginers for unity scripting?
      and how you learn Unity Scripting?

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Well I started out with TH-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.

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

    Thank you. Success for your channel. Gbu

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

    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 ปีที่แล้ว +3

      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 ปีที่แล้ว +1

      @@gamedevel22 Thanx alot it's work

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

    amazing technic..thank you
    I follow this method but don't know how to make reset button

    • @gamedevel22
      @gamedevel22  3 ปีที่แล้ว

      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 3 ปีที่แล้ว

      @@gamedevel22 its okay, thanks

    • @johanalmansyah6140
      @johanalmansyah6140 3 ปีที่แล้ว

      @@gamedevel22 but for AddPoints function even finish is true, it just still continue at OnMouseUp ()

  • @arthurlanapereira
    @arthurlanapereira 3 ปีที่แล้ว +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?

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

    It's So Great. Thanks

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

    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?

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

    Great tutorial! How would I load a new scene after all objects have been placed into their correct positions? Thanks!

    • @gamedevel22
      @gamedevel22  3 ปีที่แล้ว +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 3 ปีที่แล้ว +2

      @@gamedevel22 Hey, I got it to work! Thanks for helping me out!

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

      Glad it worked!

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

    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 ปีที่แล้ว +1

      Hey thanks a lot! Are you sure you have the colliders attched and checked the Script for mistakes?

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

      @@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 ปีที่แล้ว +1

      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

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

    Great job :)

  • @yadwinderkaur
    @yadwinderkaur 3 ปีที่แล้ว +3

    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  3 ปีที่แล้ว +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 3 ปีที่แล้ว

      @@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.

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

    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 4 ปีที่แล้ว

      I have the same problem

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Have you tried using localposition when moving the sprites?

  • @الجوهرةالصغيرة
    @الجوهرةالصغيرة 3 ปีที่แล้ว +1

    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

    • @الجوهرةالصغيرة
      @الجوهرةالصغيرة 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

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

    Thanks this what i need

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Awesome nice to hear that😁

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

    THank you! :D

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

    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 4 ปีที่แล้ว

      I have the same

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Feel free to send the code of yours in our Discord Server and myself with other Developers can have a look

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

    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

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

    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

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

    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  4 ปีที่แล้ว

      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 4 ปีที่แล้ว

      @@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 4 ปีที่แล้ว

      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"

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

    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 ปีที่แล้ว +1

      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?

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

    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 2 ปีที่แล้ว

      @@LastGamerName cursor is faster

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

    How correctForm variable gets set? can't figure it out, getting correctForm has not been assigned...

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

    Hye, I havesome problems. Why my object all positioned at the center when play and how to adjust mouse speed? Thank you!

    • @yigitcam1696
      @yigitcam1696 4 ปีที่แล้ว

      i got the same issue !!
      have u got any solutions ?

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

      if you are in 3d, the solution maight be putting the Camera on Orthografic

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

    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 ปีที่แล้ว +1

      localPosition.x is the position of the object that the script is attached to.

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

    my man from germany

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

      Haha you think so?

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

      @@gamedevel22 when you searched for pronounciation there were some words in german

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

      hehe great observation bro! True I grew up in Germany but I life in Greece currently

    • @Benjihalk
      @Benjihalk 4 ปีที่แล้ว

      ​@@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  4 ปีที่แล้ว

      I don't really get that..In order to have other images just replace the Sprite

  • @deepgames9091
    @deepgames9091 3 ปีที่แล้ว

    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.

  • @sofiejohari5028
    @sofiejohari5028 3 ปีที่แล้ว

    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?

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

    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  4 ปีที่แล้ว +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

  • @Zyugo
    @Zyugo 3 ปีที่แล้ว

    Alternately, you could use Vector2 at most parts since the z-axis is useless in 2D games.

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

    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

  • @eldonedigo7942
    @eldonedigo7942 3 ปีที่แล้ว

    Where was mousePosition declared because the cord is giving me an error
    Input does not contain a definition for mousePosition

  • @waldanrazip1224
    @waldanrazip1224 3 ปีที่แล้ว

    i already follow everything but it doesn't work. Object can't snap into the black places...

  • @rathanhv4676
    @rathanhv4676 4 ปีที่แล้ว

    Thank u so much sir

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

    Can anyone pls provide whole code of the above tutorial?

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

    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  4 ปีที่แล้ว +2

      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!

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

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@gamedevel22 well yours didnt work because I had some other script that used the camera, so I kinda made my own lol Thanks tho ^^

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

    I'm stuck at moving the object. I don't know why. Maybe because I use picture as an object.

  • @1234yokee
    @1234yokee 3 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +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 ❤

  • @momozaki4453
    @momozaki4453 3 ปีที่แล้ว

    7:32 After you display them, how can you swap between each other?

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

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

    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

  • @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 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +2

      //mousePos = Camera.main.ScreenToWorldPoint(mousePos);
      I turned this off and then it worked

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

      @@tiaraluna33 thanx a lot ☺️

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

    Can you please help me after i finish to match all the objects the game stopped it says " Transform child out of bounds"

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

    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 ปีที่แล้ว +1

      ​@@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.

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

    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  4 ปีที่แล้ว +1

      Hahaha that's why I use slimes for the new drag and drop video 😂

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

    How to reset all game objects position on click event?

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

      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 😎

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

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@gamedevel22 thank you soo much, I appreciate that

  • @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

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

    is it possible to randomize the positions of the silhouettes?

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

    why my object can’t snap to the drop place

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

    my sword are not going back to the start positions i copy your each and every step please help

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

      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 ปีที่แล้ว +1

      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!

  • @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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +2

      The most common mistake is a typo somewhere in the code 😐

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

      @@gamedevel22 I'm just learning, but dude, guys like you make a lot for people like me!
      I really appreciate it

  • @ekmalhakimi2652
    @ekmalhakimi2652 4 ปีที่แล้ว

    I'm cannot drag into the correct box how to fix it

  • @anouk6869
    @anouk6869 4 ปีที่แล้ว

    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 ปีที่แล้ว +1

      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!

  • @siomai7199
    @siomai7199 3 ปีที่แล้ว

    Does GetMouseButtonDown works on Android too?

  • @ronin6158
    @ronin6158 3 ปีที่แล้ว

    can you use onmousedrag ?

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

    why my item still can't move ?

  • @matheusscarpim5167
    @matheusscarpim5167 4 ปีที่แล้ว

    hello could you give me the script? because mine is giving problems with bad arguments

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

    can this be done in 3d?

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

    where can i find source code ?

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

    I just love u

    • @gamedevel22
      @gamedevel22  4 ปีที่แล้ว

      Hehe thanks I guess!

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

    SAWD
    Unexpected laugh.

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

      Haha thanks for the laugh 😂
      I uploaded a new drag & drop video today..have a look it may help you

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

    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.

  • @ryana.9821
    @ryana.9821 4 ปีที่แล้ว +1

    swordddd

  • @charlesferry9465
    @charlesferry9465 4 ปีที่แล้ว

    Code please lazy😅

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

    💋

  • @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 2 ปีที่แล้ว

    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)