two-dimensional area overlay / collision

alt text
Green short cube is moving in front of player character just above the ground - it can be rotated when holding ‘q’ and ‘e’ buttons. After mouse button 0 goes up a tall cuboid prefab is being instantiated just above the ground, with it’s rotation and position equal to those of the green cube.

Green cube is just a game object with mesh - it doesn’t collide with anything and has it’s y position dependent on terrain height. I want to make variable private bool areaOverlay = true; whenever green cube collides with other objects such as trees, prefabs instantiated with mouse button 0, walls buildings etc, so I can make an if statement and disable the option to create new prefabs.

I was thinking of somehow checking if 2 dimensional area (x and z axis) made by four or more points is in the same space as area of other objects with certain tag/layer/script.

What’s the easiest way to do it?

Colliders are probably the easiest because you can’t do this calculation based on the center of an object or raycast point. You need to know if the edge of the cube is touching anything. That is, by definition a collision. You could do a raycast algorithm, but then you would still need colliders.

The only other way i can think of is to use a grid-bases system and update a 2D array so it knows where things are in the game world, like that tree, then test against it as the green cube moves. You’d probably want some sort of world scan at game start to populate the 2D array. This would probably be the way to go if you can’t add colliers to everything. You would need the grid to match the cube and all objects in the world would have to obey the grid when being placed (though you can make the grid smaller, like 4 squares for the size of the cube - basically adding resolution)