Rotation from another object

I am trying to get one object’s rotation relative to another object, in euler angles as a degree value between (0 to 180) or (0 to -180). Ultimately just need the Vector3.y axis.
_
If the camera was looking directly towards the object it would give a 0 deg, and if you were looking directly away in the opposite direction it would give 180.
_
I am not trying to rotate any of the objects, just need to log this value.
_
Any help would be appreciated, thanks!

Since you only care about the angle on a single axis, I’d recommend using Vector3.SignedAngle.

// Get Y angle between A and B
float yAngle = Vector3.SignedAngle(vecA, vecB, Vector3.up)

The above would give us the angle difference between those two vectors, so we can change it slightly to find whether A is looking at B. You’d just substitute in your camera’s transform here for transformA and the object in question for transformB.

// Get Y angle between A's forward and the vector going from A to B
Vector3 aToB = transformB.position - transformA.position;
float yAngle = Vector3.SignedAngle(transformA.forward, aToB, Vector3.up)