public class gun : MonoBehaviour {
public Transform body;
private float lastAngle;
void Update () {
Plane playerPlane = new Plane(new Vector3(0,1,0), transform.position);
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float hitdist = 10.0f;
if (playerPlane.Raycast (ray, out hitdist))
{
Vector3 targetPoint = ray.GetPoint(hitdist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
float angle = Quaternion.Angle( targetRotation, transform.rotation );
transform.RotateAround(body.transform.position, body.transform.up,angle*0.1f);
}
}
}

Thera are two methods of doing this:

transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, time.deltaTime()) - good solution but problem is when vehicle turns over because turret is tring always to go straight to the mouse point so it looks like the turret is separating from body.

transform.RotateAround - this is great because no matter what is going on with vehicle the turret is always in place and turning only in Y-axis looking from body of vehicle, But !!!. Angle from Quaternion.Angle has only positive values from 0 -179 and 179-0. So in this demo I can only turn right with turret because angle has positive values, turning left causes that the turret goes … right with angle
Now … I have no idea how to jump this problem.

RotateTowards() works the same as Quaternion.Slerp … unless I’m doing something wrong, it’s rotating toward mouse position when vehicle turns over, turret separates from body of vehicle
RotateAround is the best solution because it gets point of rotation and vector3 of through point. So no matter what is going on with vehicle ( can fly in every directions and rotations ) turret is always in same position in relation to body. But this angle … I have an euler angle but only positive values.