Limiting how high or low a cannon can aim

I’m trying to make a tank barrel aim up and down but I’m not sure how to get the barrel to stop when it reaches a certain point. I’d rather not use colliders to do this.

Thanks

How did you rotate your cannon? It is the key to you limiting it

void Update ()
{
var ud = Input.GetAxis(“TurretUD”) * Time.deltaTime * m_BarrelSpeed;
transform.Rotate(0, ud, 0);

Currently using this to rotate it

You can use Mathf.Clamp() to clamp the value between 2 points ?

I’m having the same problem and use the same method to rotate my cannon.

I have tried with Mathf.Clamp and my cannon goes crazy.

public float turnSpeed = 1f;
public float maxAngle = 100f;
public float minAngle = 89f;

private float currentRotation;

Transform myT;

// Use this for initialization
void Start ()
{
    myT = transform;
}

// Update is called once per frame
void Update ()
{
    currentRotation = Input.GetAxis("Cannon") * turnSpeed * Time.deltaTime;

    //currentRotation = Mathf.Clamp(currentRotation, minAngle, maxAngle);

    myT.Rotate(-currentRotation, 0, 0);
}

My cannon spins like crazy and the the rotation is not restricted.

x = *