making bullet go travel at angle fired and limit gun rotation in Unity C# version 5.2 2D

I have two scripts.

rotate gun:

using UnityEngine;
using System.Collections;

public class rotateGun : MonoBehaviour
{
    public float rotateSpeed;
    public float  minRotate, maxRotate;
    public float noRotation;

    void start() { }

    void Update()
    {

        if (Input.GetKey(KeyCode.D))
        {
            transform.Rotate(0.0f, 0.0f, -rotateSpeed);
        }
        if (Input.GetKey(KeyCode.A))
        {
            transform.Rotate(0.0f, 0.0f, rotateSpeed);
        }
    }
}

and fireGun:

using UnityEngine;
using System.Collections;

public class FireGun : MonoBehaviour
{
    public GameObject shot;
    public Transform shotSpawn;
    public float fireRate;
    private float nextFire;
    public float fireSpeed;
    private GameObject cloneShot;
    public Transform arm;
    public float Direction = 0;

    void Start ()   {  }

    void Update ()
    {
       if(Input.GetKey(KeyCode.Space) && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            cloneShot = (GameObject)Instantiate(shot, shotSpawn.position, shotSpawn.rotation);
            cloneShot.GetComponent<Rigidbody>().velocity = new Vector3(fireSpeed,Direction);
        }
        if (arm.transform.rotation.z > 0 && arm.transform.rotation.z < 90)
        {
            Direction += 1;
        }
        if (arm.transform.rotation.z < 0 && arm.transform.rotation.z >350)
        {
            Direction -= 1;
        }
    }
}

in rotateGun i need to limit the rotation of the z axis in side view (90 & 350)

in fireGun i need to fire the bullet in the degree the gun’s rotation on the z axis.

I have tried for weeks to fix these and have not found anything.

Answers are appreciated thoroughly!

Thanks!!

If you want to clamp a value between x and y, you have to use Mathf.Clamp,

Using this, the clamped value will never be less than the minValue (90f), neither more than the maxValue (350f).

And for the firing direction, I had not tested but I think you could do this… (line 13 in your code)

cloneShot.GetComponent<Rigidbody>().velocity = arm.transform.forward;

… since forward is the z vector.