How to make a drag and drop game in Unity

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

КОМЕНТАРІ • 90

  • @daniellaplanagimeno3927
    @daniellaplanagimeno3927 11 місяців тому +5

    A good note for everyone, if you are trying to use this scripts for moving objects in a canvas, use OnPointerDown instead of OnMouseDown because canvas is a different element that in Unity terms is not inside screen so detecting mouse position in canvas will get confused

  • @fuzeworksit6465
    @fuzeworksit6465 2 роки тому +7

    I don't usually comment but this was great man. I work as an IT Manager for a school and I'm learning to use Unity to build some games for the kids. This was super helpful. Keep it up please! 💪💪

  • @USSR-Lenin-Stalin-Forever
    @USSR-Lenin-Stalin-Forever Рік тому +1

    Thanks for the lesson, the only remark is that in the middle of the lesson we started making Spawn Manager without completing the implementation of drop, because of this it was hard to go down from one implementation to another. I think it was necessary to do Drag and Drop first and then show how to implement it through Spawn Manager.

  • @rhalferty
    @rhalferty 2 роки тому +5

    Love your videos. So simple, but so helpful. They nail down the basics with easy to follow examples.

  • @jadonmullinex9389
    @jadonmullinex9389 2 роки тому +3

    I recently found your channel... you are my new favorite Unity Dev channel!
    I'm working on a Mobile Kids Game and this is perfect! Love your content!

  • @amelialewey9221
    @amelialewey9221 Рік тому +1

    This helped me start on a food assembling game! Thank you for uploading this video!

  • @noobcraft5712
    @noobcraft5712 3 роки тому +3

    Now I know how to add sounds to my game. :)

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

      I would follow up with his longer explanation of using a AudioManager, such as the Structured video.
      This gives you more flexibility and can adding settings later.
      You can also spawn an audio prefab, and initialize it, with your sound as an alternative.

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

      @@micaiahstevens8840 thanks

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

    thank you so much for such wonderful and easy to follow tutorial.. waiting to see another kids game tutorial, maybe coloring games?

  • @bluepenguin_01
    @bluepenguin_01 Рік тому +1

    great tutorial, thanks man

  • @Aurillia
    @Aurillia 2 роки тому +4

    Tarodev: "Hopefully this helped you on your way to making whatever game it is, probably a kiddy game..."
    Meanwhile, here's me using what I learned from this video to swap weapons and ammo types around in my endless shooter game 👀

    • @Tarodev
      @Tarodev  2 роки тому +3

      You're abusing the power!!

  • @keziavb
    @keziavb 3 роки тому +3

    hi, this is a great tutorial, thank you so much! you're awesome

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

      Glad I could teach you something :)

  • @nehal_chandra2777
    @nehal_chandra2777 2 роки тому +6

    my brain is too dirty for this

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

      I recently found Tarodev and love his content.
      I am HOPING its an accent, my wife was like he is NOT saying what I think he is saying.
      I can't even think how to say 'Slot' correctly. Its like Slaat, without the 'u' sound.

    • @spekticat
      @spekticat 4 місяці тому +1

      What did he say about my parents

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

    Your work is great

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

    Thanks man, your video is my lifesaver

  • @Ottiya
    @Ottiya 2 роки тому +4

    Thank you so much for this! This is awesome :) If you'd be so kind to help:
    How would you spawn just one set of slot + piece (e.g. the #1 slot and #1 piece) instead of a random number from a list?

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

    Thank you! Perfect clip!!! Awesome! AMAZING!

  • @katilehtonen614
    @katilehtonen614 Рік тому

    this is a great tutorial, but I was just wondering how could I make a good ending for a game like this? Like how to maybe restart or make something nice happen on a screen after every piece have been moved to their right slots? And I am still a beginner so I am not sure in what script something like that needs to be written? Maybe the manager?

  • @andubunea9627
    @andubunea9627 3 роки тому +6

    Can you make a video on how you made such good graphics in unity 3d ?

    • @Tarodev
      @Tarodev  3 роки тому +4

      I sure can! Stay tuned :)

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

      @@Tarodev very cool

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

      @@Tarodev OH just a recomandation you can make a discord server for subscribers to talk hang out give video ideas and stuff

  • @mactram7293
    @mactram7293 8 місяців тому

    tk very much, it help me so much

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

    you are my hero

  • @dragonarc_gaming
    @dragonarc_gaming Рік тому

    15:19 can you tell me what does this do? -> spawnedPiece.Init(spawnedSlot);
    I don't really understand how do you spawn the same sprite on both puzzle piece and slot piece.

  • @rubenvictorcallacondobeliz7135
    @rubenvictorcallacondobeliz7135 3 місяці тому

    I have a question, why when you pull the image to the work screen does it look like SPRITERENDERER? Because when you pull an image it is only set as an image, is it possible that you have your Unity development environment configured differently? Or is it different in the new versions?

  • @shuganyaravi6765
    @shuganyaravi6765 Рік тому

    Hi thank you so much for the video...how do I rearrange the puzzle piece

  • @jonecabelchev3719
    @jonecabelchev3719 Рік тому

    Great videos! I learn a lot about unity from you. Appreciate it, please keep up the good work 🙇‍♂
    I have one question though and this is kind of confusing me at the moment... I have found two approaches to implement drag and drop. One is to use sprites with box collider. And the other one is images with event system.
    What is the correct way to implement drag and drop? Or maybe in which case which approach to use?
    For example, you implement the drag and drop directly on sprites with box collider. But I couldn't make this to work on images.
    So another approach - drag and drop for images using the Event System and implement the appropriate handlers.
    Please advise. Thank you!!!

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

    That's great, thank you!!!! But how to finish this game, I mean It would be nice to see the next level (scene) or a win panel after we fullfill empy slots. How to do this?

  • @jaybob19904
    @jaybob19904 Рік тому

    I am having an issue I followed along but when I go to grab the piece it sets the transform to that of the camera and there was a point when it didn't move at all but was reacting to the OnMouseDown

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

    Thanks for your time and for this tutorial. Very handy. I'm facing some problems with the puzzle pieces since they don't move. I can listen the sound but the pieces are stuck. I have reload many times this video but could not figure it out.

  • @georgebowen2555
    @georgebowen2555 Рік тому

    I have an issue where the Pieces and slots are spawning in but arent showing on the camera?

  • @yannickgervais240
    @yannickgervais240 Рік тому +1

    I did the same thing you did and it do not drag. The sound plays as it clicked and supposedly dropped but the sprite do not move.

    • @yannickgervais240
      @yannickgervais240 Рік тому +1

      ok, I usually use 3D project and I needed to use drag in a 3d project. This code will not work if you mode is in 3d if you do not set you main cam in orthographic mode.

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

    Hi, thank you so much for this! But i have a question. how do I only spawn a new puzzle piece after it has collided with its puzzle slot?

  • @pramothr301
    @pramothr301 Рік тому

    Hello Tarodev,
    Thank you very much for your video, it was a good example for my project. I am developing 2D game, implementing the same concept drag and drop. I wanted to know how to re-arrange the objects(i.e., puzzle pieces). Can you please help with this..

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

    Hi, this is awesome! Liked and Subscribed. Is there a way to show victory panel when they placed all of them in the slot correctly. Thank you in advance.

  • @Agentti_Kowalski
    @Agentti_Kowalski Рік тому

    my transfrom.postion is not moving the character but i can hear the drop and pickup sounds

  • @michael.corlenome
    @michael.corlenome 2 роки тому

    How can I drop the object to where my mouse dropped it instead of where it originally started

  • @睾大强
    @睾大强 Рік тому +1

    where i can get those auido source?

  • @avia4281
    @avia4281 11 місяців тому

    Can you please make a simple felt game for children. Example 1 tree and 2 apples able to group and shake tree with apples and after remove one apple and shake tree group with 1 apple then no apples. Apples can lie on floor.

  • @datd4063
    @datd4063 3 роки тому +2

    Hello Tarodev,
    thanks for your tutorial. I wanted to know whether you can make a tutorial where you can drag and drop the items. In Addition the item should rotate with a mouse movement. Thank you in advanced.

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

      Do you mean adding a bit of swing to it as you move it left and right? You could compare current position with the position n seconds ago and lerp rotation based on the delta.
      If you mean rotating the more you slide it across the screen you could just add rotation based on the x position.
      Or did I miss your objective completely?

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

      @@Tarodev Hello Tarodev, thanks for your reply. I meant for example: Rotate the figure 6 to the figure 9 with a 180 degree mouse movement.
      I tried to recreate a tangram game, where you have to move several pieces and rotate it to complete a big geometrical shape.

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

      @@Tarodev A example can be found on this website: mathigon.org/tangram

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

      @@datd4063 Ah! So to achieve that, each shape should have an object as a child which will contain the outline and the handle which pops up. When the player clicks the shape you enable the child object. Once they grab the rotation handle it should be as simple as rotating the shape on its pivot... If you put the rotation handle on the up axis you could simply do something like:
      transform.up = Camera.main.ScreenToWorldPoint(Input.mousePosition);
      Come into my discord if you need additional clarification :)

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

      @@Tarodev Thank you. I will try it. I also joined your discord server.

  • @jayskylark8692
    @jayskylark8692 6 місяців тому

    How did you export it to a phone or a table?

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

    What do you have in your Main Camera folder? How did you make your Scene the same background as your Game

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

      I took a look and it was HARD to tell, he could have done it multiple ways.
      A Camera with the settings to SolidColor (then choose a Green Color)
      A Canvas with an Image.
      A GameObject with a SpriteRenderer (More in line with how he coded the rest of the game)
      Either way you need some Image, or SpriteRenderer to set the sprite to a graphics, I like png's
      Looking at the video again, it seems more solid color, but all three are options.
      Than size, place according to your game.

  • @mertarslang
    @mertarslang Рік тому

    Hello,
    First of all, thank you very much for your video, it was a good example for my project assignment, but I have a question. I'm developing a 3D game and I want to implement this puzzle you made there. When I brought it directly, I noticed that there were problems with the dragging. For this reason, I want this puzzle game to appear as a pop-up when I create a UI screen and click on any object in the game. Is it possible?
    I hope you will answer, I wish all the best!

    • @mertarslang
      @mertarslang Рік тому

      I guess, "How can I do it on Canvas?" I'm talking about this.

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

    Hello, great tutorial thank you I did not know it could be so easy.
    Do you know if it is easily feasible in unity to cut a "cake" ( a disk ) into several parts ( quarters for example ) ? And then drag and drop those parts ?

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

      That sounds exactly like a 'Radial Menu', and then you apply your scripts and logic along the same lines as this video.

  • @navodyaliyanage6297
    @navodyaliyanage6297 2 роки тому +2

    can u plz share the github link as well?

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

    i try to copy what you do sir but nothing happen. can you guide me why sir?

  • @lirikshack7672
    @lirikshack7672 Рік тому

    urgent help, how do I add score to this script?

  • @睾大强
    @睾大强 9 місяців тому

    can u make a Visual Scripting verson of this ?

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

    Sir, can we random the place of object? Thank you so much

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

      Will include both replies to address random, see other commenter
      transform.position = Random.insideUnitSphere * 5;
      (This will need to worked around a bit if your in UI or Scene view placement of your game.)
      This DOES run into overlap, but that's a BIT more complicated.

  • @NKGReuploadz
    @NKGReuploadz Рік тому +1

    Can You Add Numbers Game To Google Play?

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

    i have no function order by for slotsPrefabsSlots List ?

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

      This is because you need to include..
      'Using System.Linq'
      At the top of your files with the other using.

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

    Can you share the scripts......Its hard to see in this video because of my slow internet connection.

  • @uroojfatima9169
    @uroojfatima9169 Рік тому +2

    NullReferenceException: Object reference not set to an instance of an object
    PuzzlePiece.OnMouseUp () (at Assets/Scripts/PuzzlePiece.cs:44)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32)
    Facing this error

    • @Sam-pnk
      @Sam-pnk Рік тому

      I'm facing the same problem! How did you fix it? :(

    • @zelderon7195
      @zelderon7195 Рік тому

      I have the same problem

    • @uroojfatima9169
      @uroojfatima9169 Рік тому

      ​@@Sam-pnkapplied some conditions . i'll share my puzzle piece.cs

    • @MaritzaAlfonsoRodriguez
      @MaritzaAlfonsoRodriguez 11 місяців тому

      @@uroojfatima9169 how did you solve it?

  • @spekticat
    @spekticat 4 місяці тому

    Oh he said SLOT

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

    how can i set the position of the the dragndrop button ? not to random place the position

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

      Will include both replies to address random, see other commentor
      Vector3 pos;
      One way is to set the pos.x = Rnadom.Range(-25, 25)
      myObject.transform.position = pos;
      (Since you can't change position directly)
      and do that for each x/y/z you want, depending on how you see your scene up.
      This DOES run into overlap, but that's a BIT more complicated.

  • @bharatgupta1937
    @bharatgupta1937 Рік тому

    Guys can someone help me with the sprites folder?

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

    I cant drag object.
    Object not set to an instance

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

      not set to an instance, was discussed how to figure this out in another video.
      Basically Unity is saying you did not setup your object in the editor, for prefabs and sprite renderers and such.

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

    What do you keep saying "slotch"?
    What's a "slotch"?

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

    There's no point in this video as you don't show how this system works on the canvas.

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

      I'm sorry it wasn't what you expected (a canvas 101 tutorial, I assume)

  • @DannyBoy443
    @DannyBoy443 Рік тому

    I'm not complaining, but again, can someone tell me why people feel the need to put themselves on camera during these tutorials? No offense but we don't need that. Just hearing you and seeing your walk through is enough.

    • @Tarodev
      @Tarodev  Рік тому +1

      No offence taken, this is your opinion. Can't please everyone.
      I suppose if you make a tutorial channel, you can create videos exactly to your liking?

  • @zelderon7195
    @zelderon7195 Рік тому

    NullReferenceException: Object reference not set to an instance of an object
    PuzzlePiece.OnMouseUp () (at Assets/Scripts/PuzzlePiece.cs:47)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32) (at /Users/bokken/buildslave/unity/build/Modules/InputLegacy/MouseEvents.cs:208)