Find object with tag in small distance and delete found object and itself.

Hello! So I have this code, that randomly spawns pipes and then deletes the transform it spawned at, so that something doesn’t spawn there again, this works. There is a problem, however:

If there is a pipe with 4 openings, when spawned that would leave 3 openings. The problem here is that it doesn’t check if there is a connection (So with tags, for example Right would connect to Left)

How do I check if there is something in range, while also not checking the whole world for objects with some tag, then check if one of those are in range. I don’t want this because it is inefficient, logical I hope?
I cannot check if there is ANY sort of pipe in any direction, because some pipes don’t have a connection that way, and that would leave an open pipe.

You can use OverlapCircleAll for 2d or OverlapShereAll for 3d then you check the tags, then delete the object.

Alternatively you could use FindGameObjectWithTag and then check the distance with Vector2.Distance for 2d or Vector2.Distance for 3d.

I think the 1st may be more efficient, but really depends on a lot of factors.