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
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! 💪💪
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.
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.
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 👀
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.
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?
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?
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.
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?
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!!!
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?
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
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.
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.
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..
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.
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.
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.
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?
@@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 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 :)
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.
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!
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 ?
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.
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
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.
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.
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.
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)
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
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! 💪💪
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.
Love your videos. So simple, but so helpful. They nail down the basics with easy to follow examples.
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!
This helped me start on a food assembling game! Thank you for uploading this video!
Have fun 😊
Now I know how to add sounds to my game. :)
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.
@@micaiahstevens8840 thanks
thank you so much for such wonderful and easy to follow tutorial.. waiting to see another kids game tutorial, maybe coloring games?
great tutorial, thanks man
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 👀
You're abusing the power!!
hi, this is a great tutorial, thank you so much! you're awesome
Glad I could teach you something :)
my brain is too dirty for this
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.
What did he say about my parents
Your work is great
Thanks man, your video is my lifesaver
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?
Thank you! Perfect clip!!! Awesome! AMAZING!
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?
Can you make a video on how you made such good graphics in unity 3d ?
I sure can! Stay tuned :)
@@Tarodev very cool
@@Tarodev OH just a recomandation you can make a discord server for subscribers to talk hang out give video ideas and stuff
tk very much, it help me so much
you are my hero
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.
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?
Hi thank you so much for the video...how do I rearrange the puzzle piece
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!!!
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?
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
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.
I have an issue where the Pieces and slots are spawning in but arent showing on the camera?
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.
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.
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?
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..
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.
my transfrom.postion is not moving the character but i can hear the drop and pickup sounds
How can I drop the object to where my mouse dropped it instead of where it originally started
where i can get those auido source?
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.
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.
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?
@@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.
@@Tarodev A example can be found on this website: mathigon.org/tangram
@@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 :)
@@Tarodev Thank you. I will try it. I also joined your discord server.
How did you export it to a phone or a table?
What do you have in your Main Camera folder? How did you make your Scene the same background as your Game
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.
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!
I guess, "How can I do it on Canvas?" I'm talking about this.
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 ?
That sounds exactly like a 'Radial Menu', and then you apply your scripts and logic along the same lines as this video.
can u plz share the github link as well?
i try to copy what you do sir but nothing happen. can you guide me why sir?
urgent help, how do I add score to this script?
can u make a Visual Scripting verson of this ?
Sir, can we random the place of object? Thank you so much
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.
Can You Add Numbers Game To Google Play?
Of course you can 😊
Link?
Add Multiple Levels
i have no function order by for slotsPrefabsSlots List ?
This is because you need to include..
'Using System.Linq'
At the top of your files with the other using.
Can you share the scripts......Its hard to see in this video because of my slow internet connection.
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
I'm facing the same problem! How did you fix it? :(
I have the same problem
@@Sam-pnkapplied some conditions . i'll share my puzzle piece.cs
@@uroojfatima9169 how did you solve it?
Oh he said SLOT
how can i set the position of the the dragndrop button ? not to random place the position
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.
Guys can someone help me with the sprites folder?
I cant drag object.
Object not set to an instance
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.
What do you keep saying "slotch"?
What's a "slotch"?
There's no point in this video as you don't show how this system works on the canvas.
I'm sorry it wasn't what you expected (a canvas 101 tutorial, I assume)
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.
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?
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)