Get angle between two transforms in a single plane

I have two game objects in a scene.

I’m aware that I can use the .angle function to get the angle between the two objects, however this is a single angle in 3d. What I want is to get two different angles, one in the vertical plane and one in the horizontal plane.

So, if I had one gameObject, and another 20 degrees up and 30 degrees to the right, I would like to get:

Vertical = 20; Horizontal = 30;

Thanks.

If I understand your question correctly, I think you have this setup:

alt text

It should be sufficient for you to do the following:

Vector3 delta = gameObject2.transform.position - gameObject2.transform.position;
Quaternion look = Quaternion.LookRotation(delta);

float vertical = look.eulerAngles.x;
float horizontal = look.eulerAngles.y;