Check if an object is at a relative position?

Is there a javascript function where a object checks if another object (or tag) is at a certain position relative to itself, and then if so does a certain action?

For example, when a corridor segment is created, it checks if there is a segment in front (say 20m) of it. If there is, it will either turn left or right. The same applies if there is a segment to its left, it will go straight or right, etc.

You could try either Physics.Raycast, or Vector3.Distance.

Don’t think there is an existing script that suits your needs, but you should be able to write one yourself. You could use raycasts or colliders to test if there are obstacles in front of your newly created corridor.