Rotation of an object towards another, but only up and down

Hi,

I’m making a game where I have a tank and I need to move the gun so that it points at the target.

I already have the turret rotation movement figured out, but I need to figure out the gun movement. But only up and down. The sideways movement is what the turret does. Unfortunately, I found that LookAt needs at least two axes, otherwise the up and down direction only works in 90 degrees.
How can this problem be solved so that the cannon only rotates up/down and completely ignores left and right movement?

I’ve been drowning in the internet for days trying to find a solution to the problem, but to no avail. Thanks for the help.

using UnityEngine;
public class gunRotate : MonoBehaviour
{   
	public GameObject target;
	void Start()
	{
		target = GameObject.Find("MousePosition");
	}
	void Update()
	{
		Vector3 targetPosition = new Vector3(
			target.transform.position.x,
			transform.position.y,
			target.transform.position.z);

		transform.LookAt(targetPosition);
	}
}

TurretController.cs

using UnityEngine;
public class TurretController : MonoBehaviour
{
	[SerializeField] Transform _chasis = null;
	[SerializeField] Transform _turret = null;
	[SerializeField] Transform _gun = null;
	[SerializeField] Transform _target = null;
	[SerializeField] float _turretDegreesPerSecond = 45;
	[SerializeField] float _gunDegreesPerSecond = 10;
	[SerializeField] Vector2 _gunRotationRangeX = new Vector2( -20 , 10 );
	void Update ()
	{
		Vector3 targetPos = _target.position;

		// turret control:
		Vector3 targetPosTurret = new Vector3( targetPos.x , _turret.position.y , targetPos.z );
		Quaternion turretRotationFinal = Quaternion.LookRotation(
			forward:	targetPosTurret - _turret.position ,
			upwards:	_chasis.up
		);
		float turretDegreesToFinal = Quaternion.Angle( _turret.rotation , turretRotationFinal );
		_turret.rotation = Quaternion.Lerp(
			_turret.rotation , turretRotationFinal ,
			( _turretDegreesPerSecond / turretDegreesToFinal ) * Time.deltaTime
		);

		// gun control:
		Vector3 targetPosGun = _turret.InverseTransformPoint( targetPos );
		float gunAngleFinal = -Mathf.Atan2( targetPosGun.y , targetPosGun.z ) * Mathf.Rad2Deg;
		float gunAngleLimited = Mathf.Clamp( gunAngleFinal , _gunRotationRangeX.x , _gunRotationRangeX.y );
		_gun.localRotation = Quaternion.Lerp(
			_gun.localRotation ,
			Quaternion.Euler( gunAngleLimited , 0 , 0 ) ,
			Mathf.Abs( _gunDegreesPerSecond / gunAngleLimited ) * Time.deltaTime
		);
	}
}

Transform hierarchy:

+ chasis
| chasis mesh
| + turret
| | turret mesh
| | + gun
| | | gun mesh