Merge Objects In 2D Unity Game | Create A New Object Dragging One Object to Another Combining Them

Аватар автора
ZOTOV
How to merge two objects to get a new one? That is what this video is about. TO BLAST! - My New Fun Relaxing Puzzle Game Available On Google Play Store Not only your hands are responsible for aiming ability :-) Logitech G305 LIGHTSPEED Wireless Gaming Mouse If you like what I&doing then you can support me through or here Thank you) Here what this video is about. How to merge objects to create a new one? Let me show a very simple way. Here I have an empty project. Let’s add some gameobjects. Those will be an acorn, an oak, and a Rocket of course. These gameobject gonna need box colliders to detect mouse click. And also to detect collisions between each other they will need a rigidbody 2d. Set gravity scale to 0 or they will fall down. Ok. One simple script helps us to make this all work. OnMouseDown is invoked when you press left mouse button over objects collider. That’s why we need those colliders. Without collider it will not work. So when it happens I kind of declare that I hold mouse button down ‘cause I&gonna need some checking when I release it. Also here I calculate some offset between mouse position and center of game object I’m going to drag. Without this offset my gameobject will jump upto mouse pointer when I start to drag it. OnmouseDrag is invoked when I drag an object with mouse holding down left mouse button. Everything is pretty simple here. I get Mouse position and set objects position to it using that offset. OnMouseUp is invoked when mousebutton...

0/0


0/0

0/0

0/0