How to make and snap a hole in wall in run time

Hi! I’m a first year college student and very new in Unity. I tried making this game where the user can build their own blueprint of their house. I can already make walls during run time. Now, I want to make a hole in the said user made wall so that the user can walk around it. I use prefabs for the wall and I have a ready prefab for the door. How can I snap the my prefab door to the walls, dynamically and make a hole in it? Advance thank you!

I have the picture of the game.

Hello,

For the door “snapping”, I would use a Raycast to find the wall, then simply instantiate the door at the wall x,z location. You can get mesh normals from a Raycast, and they can inform rotation if you need the door rotated.

The “hole” is a bit trickier. You could experiment with doing custom meshes either via code or using Mesh.CombineMeshes, but since you are working with straight walls it might be easier / cleaner to just use extra cube objects.

When the player places a “door”, instantiate two extra wall objects at the same location of the current wall object. Then transform the “left” wall object so that it is halfway between the door and the left adjoining wall, scaled to fit. Do the same to the “right” wall object with the right adjoining wall. Then transform / scale the third instantiated wall object above the door, and you have a door frame and it looks entirely seamless.

There are other ways to accomplish this, but this might be the simplest for a newbie. Let me know if you have questions about the math.

-Jason