I have an rectangular cube that needs to be placed between two other objects, and it properly rotates so that each end faces the two objects. Since this happens on a spherical world, the issue lies when I try to then align it to be properly facing "up". I didn't realize this before, but this code (which works on the other objects as they only need to orient once) only uses the X and Y axes. I can manually orient them properly by modifying the Z-axis in the Editor, so I know it's possible, but since they must be created procedurally that obviously isn't feasible. Changing from transform.up to down or right changes absolutely nothing.
In the following code, parent is a one of the objects it has to orient towards (which it does fine), and target is the center of the sphere.
In theory, the alignment to the two side objects should only need to use the X and Y axes, and the alignment to the center of the sphere then only needs to use the Z axis as represented in the final line of code, yet in practice this doesn't work as both alignments both want to use only the X and Y axes and ignore the Z axis.
Vector3 parentDirection = parent.transform.position - transform.position;
Vector3 targetDirection = target.position - transform.position;
Vector3 DirectionToParent = Vector3.RotateTowards(transform.forward, parentDirection, 100f, 0.0f);
Vector3 CenterDiretion = Vector3.RotateTowards(transform.forward, targetDirection, 100f, 0.0f);
Quaternion ParentRotation = Quaternion.LookRotation(DirectionToParent );
Quaternion CenterRotation = Quaternion.LookRotation(CenterDiretion );
transform.rotation = Quaternion.Euler(DirectionToParent.eulerAngles.x, DirectionToParent.eulerAngles.y, newRotation.eulerAngles.z);