How to Select, Drag and Snap with Unity3D. Works with 2D sprites and 3D objects and easy!

Поділитися
Вставка
  • Опубліковано 22 лис 2024

КОМЕНТАРІ • 43

  • @confirmed_real
    @confirmed_real 2 роки тому +1

    This video is very helpful! Thank you!

  • @ytconfino341
    @ytconfino341 3 роки тому

    great video!! very useful. can you please show or explain the trash can thing??

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому

      It is actually not that hard so probably doesn't need another video. In the DropObject where you do the check against snapPoints inside that you simply destroy(objSelected). You might not want to do this against all your snapPoints. If that is the case just create a tag and go if(snapPoints[i].tag == "yourtagname"). Then where the snap point is just put a sprite for a trash can (without a collider) so the user has a visual.
      If you can't get it working or still would like a video on it I am happy to do it :)

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому

      @@ytconfino341 Great :)

  • @cricketfandom9089
    @cricketfandom9089 3 роки тому

    Great Video really helpful

  • @elezavala
    @elezavala 3 роки тому +1

    how can you make the two cards snap together, like be attached next to eachother without dissappearing?

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому +1

      in line 53 of the code in the example you just need to apply an offset. For example use "snapPoints[i].transform.position.x - 5.0f" instead of "snapPoints[i].transform.position.x" to have it snap to 5 units to the left of the snap point. Just adjust these values until you get the cards snapping the way you want.

    • @elezavala
      @elezavala 3 роки тому

      @@DestinedToLearn thank you so much! i will try that! :)

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому +1

      @@elezavala if you did this you could actually just make every card a snap point and it would snap to the side of the card which would be a pretty simple global solution.

  • @piratedoggames1332
    @piratedoggames1332 2 роки тому

    How would I make it so only one card could be placed on a single spot?

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому

      I don't have a tutorial on that, but if you watch the part 2 of this tutorial it will give you some clues how to do it. You will just need to extend that a bit with a script which keeps track of if there are any objects at the point.

  • @o9o7_
    @o9o7_ 2 роки тому

    how can i stop objects from moving way back when i hold them // how can i keep the depth of the objects ?

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому

      Change the line in dragobject where it says camera.main.nearclipplace + 10.0f to adding a smaller amount, or put the z value you desire in there.

    • @o9o7_
      @o9o7_ 2 роки тому

      @@DestinedToLearn Yeah I figured that out thanks. I want to know how i can make the objects move once they hit the snap point.

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому

      @@o9o7_ not sure what you mean? you should just be able to grab them and move them again after snapping.

    • @o9o7_
      @o9o7_ 2 роки тому

      @@DestinedToLearn Yeah I wanted to make a correct placement for an object over a board and there are some objects that go to a certain place to get a point showing that it is the correct place, then they become undraggable. So I added tags to the code and if the tag is changed the object wont move anymore and the snap point only picks one object to make it a bit realistic and functional.

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому

      @@o9o7_ I will have a look at it as I am going to create a part 2 to tutorial this weekend. That isn't the way the script to work. I think your snapping points might have colliders on them which is what stops you picking up the object a second time.

  • @الجوهرةالصغيرة
    @الجوهرةالصغيرة 3 роки тому

    Thank you so much, I have error it says “GameObject[] does not contain a definition for length and no accessible extension method length accepting a first argument of type GameObject[] could be found

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому

      What line does it say the error is on? Have you assigned your objects in the editor? Where it says snapPoints.Length did you accidently type snapPoints[].Length?

    • @الجوهرةالصغيرة
      @الجوهرةالصغيرة 3 роки тому

      @@DestinedToLearn oh yaaaah it's fixed now !, thanks man ..
      The problem that I am facing now is in the drop that does not drop the images, in fact I have a children game that contains 3 images in the first level that must be arranged correctly according to their appearance and I do not know how to do that, I put the place of the green card you have the places of the image containers, claiming that they will interact in the same way, but it did not happen :(

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому

      @@الجوهرةالصغيرةSo you can pick up and move it around around but you can't drop? I would start to add some debug statements to try and find your problem. For example go to the drop functions and add Debug.log("Calling drop function); then when you are testing you will see if the function is being called. You can do this in different places in the code to easily see where you are at. Also if your objects you are moving are multiple objects parented together make sure only the parent has a collider not the children. IF you put your code in pastebin.pl and comment the link then I am happy to have a look.

    • @الجوهرةالصغيرة
      @الجوهرةالصغيرة 3 роки тому

      @@DestinedToLearn Thank you man , I did debug and paste the code in the link you put ,actually it's drop the pictures but there is no snap in the In the specified container for each pictures , I am afraid because I do not know how to use Unity :'(
      Anyway, here is the link for the code and I put my email for ease
      pastebin.pl/view/a9e3ff8d
      .
      .
      myjewel.907@gmail.com
      .
      .
      Thank you again,

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому

      have you assigned the snap points in the editor for the location of the 3 cards you want to order? These are just gameobjects where you want the cards to snap too when you let go if close.

  • @Airixsas
    @Airixsas 3 роки тому

    Hey dude, what do I need to change so that I could drag the object in Z plane instead of Y plane in 3D world project? Can't really find any good info on this one.

    • @DestinedToLearn
      @DestinedToLearn  3 роки тому +1

      I assume you mean move the depth back and forwards like the unity move tool? This is bit tricky because you don't have a refence of how deep you want to go. If I was going to do this I would attach depth to something like mouse wheel. I can't think of good examples of doing this without a move tool (with the xyz you can grab).

  • @coffeebean7502
    @coffeebean7502 2 роки тому

    does this work on mobile?

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому +1

      it does but only supports 1 touch. If you want to do multi-touch you will need to need to modify the code to loop thru all the touches.

    • @coffeebean7502
      @coffeebean7502 2 роки тому

      @@DestinedToLearn tried it and it worked but how do I make it so that only one object can snap to one snap point? because all of the three objects are snapping to only one snap point.

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому

      @@coffeebean7502 I would look at your drop object code. Does the incorrect snapping happen in editor too?

    • @coffeebean7502
      @coffeebean7502 2 роки тому

      @@DestinedToLearn I just copied the code, it seems that all the draggable object can snap to one snap point. Is it possible to make a specific object snap to a specific snap point? So if I try to drag and snap the wrong object to a snap point it won't snap.

    • @DestinedToLearn
      @DestinedToLearn  2 роки тому

      ​@@coffeebean7502 ohhh you are saying you want object to only snap to point. You would need to modify the way the DropObject functions and it doesn't do it as currently written. Basically you will need to take the snapping out of the mousecontroller script and put it on the object instead. I will try to make a part 2 video showing it.