hi how to merge objects to create a new one let me show you a very simple way here i have an empty project let's add some game objects those will be an acorn an oak and a rocket of course these game objects gonna need box collider to detect mouse clicks and also to detect collisions between each other they will need a rigid body to d set gravity scale to zero 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 object's
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 because i'm gonna need some checking when i release it also here i calculate some offset between mouse position and center of the game object i'm going to drag without this offset my game object will jump up to mouse pointer when i start to drag it on mouse drag 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 object's position to it using that of set on mouse up is invoked when mouse button is released when it happens i tell the script that button is released and this condition is met the main part of magic happens in ontriggerstay method which is being invoked while gameobject's collider is overlapping another collider so when it's happening i have to get names of those overlapping game objects to be able to perform merged action or not to perform so i get names here underscore divider which i will add to objects names a bit later will help
me to get the part of the name i need first part in this case which will be acorn oak or rocket when names are obtained i check if a button is released and names are equal to what i want them to i instantiate a new oak or rocket depending on certain conditions prefabs will be loaded from the resources folder which i will create in a moment that's the script i drag and drop this script to acorn oak and rocket to be able to instantiate game object i need a prefab of it and this prefab should
be put into resources folder so i create resources folder in assets folder be careful with resources folder's name just one typo will ruin the whole game once the folder is created i drag and drop my game object into it turning them into prefab now i have to rename each prefab so the script can get the part of its name and load its prefab correctly adding underscore and object word will do the job nice i can delete this game objects from hierarchy now i add an icon duplicate it three times spread them around the scene a
bit and now i can hit play to see how it works i can drag each object and when i overlap them and release the what the f i forgot to set colliders to be triggers select my prefabs and check in is trigger option now i can hit play and see how it works i can drag it and if i overlap them and release the button a new game object is created beautiful hope you like this tutorial thank you for watching and see you next time