Finding the position of an object on another object's axis

I’m trying to figure out how to derive positional data of an object relative to the position and orientation of another. Particularly I’m concerned with how far object 2 is in front of or behind object 1, based on which way object 1 is facing (its front). So if object 2 is directly to the right of but parallel to object 1, the variable would be 0, and if object 1 turned 90 degrees to the right the variable would be positive, and if it faced the opposite direction it would be negative. If object 1 is facing down and object 2 is above it, the variable would be negative; if it’s below it it would be positive, etc etc.
How could I accomplish this using only the data pertaining to the objects’ global positions/orientations?I basically just want to find out where one object’s point in space falls along the axis of another object.

Hello.

The way is maybe to make the object child of the other object, then use localPosition to know its relative position.