Need Help Limiting Rotation on Object's X axis

In my game I have 3d tanks and this script controls the up and down of the gun barrel. And i do not want the gun barrel to rotate all the way around, and i want it to stop at certain points, so how would I go about doing that?

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

public class GunMovement : MonoBehaviour {

public GameObject bobject;

void FixedUpdate () {
	if (Input.GetKey ("down")) {
		bobject.transform.Rotate (1, 0, 0);
	}

	if (Input.GetKey ("up")) {
		bobject.transform.Rotate (-1, 0, 0);

	}

}

}

Instead of using relative rotations (that is, rotating one degree up and down from your previous position), use an absolute value with a delta.

Here’s something that works. start is the local rotation at the beginning of the script, xRotation is the delta value you can rotate from start. On each update, you clamp the amount rotated by a maximum and minimum value:

public class GunMovement : MonoBehaviour {

    public GameObject bobject;

    private Quaternion start;
    private int xRotation;

    private void Start()
    {
        start = bobject.transform.localRotation;
        xRotation = 0;
    }

    void FixedUpdate()
    {
        if (Input.GetKey("down"))
        {
            xRotation++;
        }
        if (Input.GetKey("up"))
        {
            xRotation--;
        }

        // limit the rotation here!
        const int MaxAngle = 20;
        const int MinAngle = -5;
        xRotation = Mathf.Clamp(xRotation, MinAngle, MaxAngle);

        // the final rotation will be the start rotation
        // combined with the delta values
        bobject.transform.localRotation = start * Quaternion.Euler(xRotation, 0, 0);
    }
}