Directing a turret towards object

I’m trying to get a turret to direct towards an object. I tried to work with lookat, but the top of the turret then was turned towards the object instead of the barrel. Therefor I tried a different way.

This code turns now my turret:

Vector3 newPosition = target.position;
newPosition.x=0;
newPosition.z=0;
transform.RotateAround(transform.position,new Vector3(0,1,0), Time.deltaTime*smoothTime);

Though Now I need to know the location of the other object compared to the barrel of the turret. (I suppose the angle and then I can compare the Z of the object to the Z of the turret).

How can I find this angle?

I see what you’re trying to do, and it could work. It just seems like a rather circuitous way of doing it. I might try something like this.

Vector3 offset = target.position - transform.position;
Vector3 axis = Vector3.forward;
//You will probably need to change the axis.
// I know you said that it was wrong when you used look at so it's not going to be Vector3.up
//but it'll be one of the other ones.

targetRotation = Quaternion.LookRotation ( offset , axis);
//Create a rotation looking at the turret
transform.rotation = Quaternion.RotateTowards( transform.rotation , targetRotation , rotateSpeed * Time.deltaTime );
//Actually rotate towards the target.