How to rotate cannon by angles on top of a turret

Hi! I am trying to get a turret for a flying battleship game to work, but I can’t for the life of my get the elevation controls to work!

I have a 3 axis turret consisting of 2 pieces: A Turret, which turns horizontally on the Y axis, and a Cannon, which I would like to turn on the x axis. The cannon is set as a child of the turret.

The Turret’s rotation is done by a scrip that points it towards a public gameobject, which is currently set as a point attached to my camera, which is on a custom mouse based 3rd person controller. It uses a script I canalized from a Quill18 script, and uses quaterions. It works wonderfully

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TurretRotator : MonoBehaviour {

public float rotSpeed = 90f;
public float correctionAngle;
public float maxright;
public float maxleft;
public GameObject aimpoint;

//tracks the Aimpoint, as aimed by mouse
public void Update()
{
    Vector3 aim = aimpoint.transform.position;

    Vector3 dir = aim - transform.position;
    dir.Normalize();

    float yAngle = Mathf.Atan2(dir.x, dir.z) * Mathf.Rad2Deg + correctionAngle;

    //Debug.Log(yAngle);

    Quaternion desiredRot = Quaternion.Euler(0, yAngle, 0);

    transform.rotation = Quaternion.RotateTowards(transform.rotation, desiredRot, rotSpeed * Time.deltaTime);

}

}

I must admit I am not that familiar with Unity’s scripting, especially rotations, as I do not understand Quaternions very well, or how to manipulate them.

However, I am really struggling to get my turret to elevate. I have spent 2 days straight trying to get it to elevate by the angle, and cannot come up with a working script.

What I want to be able to to is to
-send it data or get data from another script, allowing both the player to manually control it as well as AIs to control it
-Rotate on the X axis to a certain degree, preferably a float. This will allow precise firing angles based on enemy ship’s movement, distance, and elevation, all calculated by some other script.
-keep the same base rotation as the Parent object, so it is facing the same direction as the turret is
-Rotate over time, instead of just instantly snapping to the desired elevation
-have a modifier that allows a certain angle to be set as the “zero” angle for cannon, this is important since my cannon’s x rotation is set as -90 to make it face the horizon, otherwise it would point straight up.

So far, I have attempted to use many methods. These have had varying levels of success, from-
-A simple script that elevated up and down with button inputs- press the button, if statement allows transform.Rotate to cause upwards or downwards rotation. Cannon stays with Parent, and keeps parents other rotations, only it’s X axis is modified. completely imprecise, could not modify to get to hover on certain angles. any attempt to make this turn towards a certain angle and stop, caused constant rotation on the X axis(just spinning around).
-A script attempting to turn Desired Angle into a Vector3, and feed it into a mechanism like the one used in the Rotation script, converting Vector3 into a Quaternion, and using a transform.rotation modifier to elevate cannon. This usually disconnected the cannon’s rotation from the turret, and often simply did not elevate the turret. often times it made my turret point at it’s natural “zero” x rotation, straight up, even with my attempts to correct this.

I am completely stumped here, and help I can get would be appreciated.

AH-HA! I figured it out!
Here is the script I made.
I found that referencing the objects exact x rotation was both difficult and unnecessary! By simply forgoing this, I found I can just elevate by degrees/frame (currently .1 and can get accurate elevations! Plus, I can access my function from other scripts so I can make a "targeting computer later on!

I am sure I will need to adjust my numbers a bit, but for now, this should work well.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TurretElevator : MonoBehaviour {

public float elvSpeed = 10f;     //not currently used, will by max elevation rate, If i chose to limit (up for debate, adds unneeded complexity
public float maxElevation = 40;  //upper elevation bound
public float depression = 5;     //lower elevation bound
private float elevation;         //holds the current elevation, in degrees
private float elv;               //holds input for Update

//this update includes a simple, tenth of a degree elevator/depressor.
public void Update()
{
    if (Input.GetButtonDown("Elevate"))
    {
        elv += .1f;
    }
    if (Input.GetButtonDown("Depress"))
    {
        elv -= .1f;
    }

    Elevate(elv);
}

// Update is called once per frame
public void Elevate(float desiredElv)
{     
    //if statement elevates, and should keep within the elevatin/depression limits
    if (elevation < desiredElv && elevation < maxElevation)
    {
        transform.Rotate(0.1f, 0, 0);
        elevation += 0.1f;
    }
    else if (elevation > desiredElv && elevation > -depression)
    {
        transform.Rotate(-0.1f, 0, 0);
        elevation += 0.1f;
    }
    else
        transform.Rotate(0f, 0, 0);
}

}