How do I make it so my gun does notshoot up and down

When I fire it will always shoot forward matter if i am looking up or down, can you help a brother out?

Here is my code:

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class gunWorks : MonoBehaviour
{
[Header(“GunSettings”)]
public float fireRate = 0.1f;
public int clipSize = 16;
public int reservedAmmoCapacity = 120;

//varibles that change during code

bool _canShoot;
int _currentAmmoinClip;
int _ammoInReserve;

//Muzzle Flash

public Image muzzleFlashImage;
public Sprite[] flashes;

//Aiming

public Vector3 normalLocalPosition;
public Vector3 aimingLocalPosition;

public float aimSmoothing = 10;

//Weapon Recoil

public bool randomizeRecoil;
public Vector2 randomRecoilConstraints;

// only need to assing this if randomize recoil is off
public Vector2 recoilPattern;

    // Start is called before the first frame update
void Start()
{
    _currentAmmoinClip = clipSize;
    _ammoInReserve = reservedAmmoCapacity;
    _canShoot = true;
}
[Header("LookingAround")]
public float mouseSensitivity = 1;
Vector2 _currentRotation;
public float weaponSwayAmount = 10;

// Update is called once per frame
void Update()
{
    DetermineRotation();
    DetermineAim();
    if (Input.GetMouseButton(0) && _canShoot && _currentAmmoinClip > 0)
    {
        _canShoot = false;
        _currentAmmoinClip--;
        StartCoroutine(shootGun());
    }
    else if(Input.GetKeyDown(KeyCode.R) && _currentAmmoinClip < clipSize && _ammoInReserve > 0)
    {
        int amountNeeded = clipSize - _currentAmmoinClip;
        if (amountNeeded >= _ammoInReserve)
        {
            _currentAmmoinClip += _ammoInReserve;
            _ammoInReserve -= amountNeeded;
        }
        else
        {
            _currentAmmoinClip = clipSize;
            _ammoInReserve -= amountNeeded;
        }
    }
}

void RayCastForEnemy()
{
    RaycastHit hit;
    if(Physics.Raycast(transform.parent.position, transform.parent.forward,out hit , 1 << LayerMask.NameToLayer("Enemy")))
    {
        try
        {
            Debug.Log("Hit an Enemy");
            Rigidbody rb = hit.transform.GetComponent<Rigidbody>();
            rb.constraints = RigidbodyConstraints.None;
            rb.AddForce(transform.parent.transform.forward*500);
        }
        catch { }
    }
}

void DetermineRotation()
{
    Vector2 mouseAxis = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));

    mouseAxis *= mouseSensitivity;
    _currentRotation += mouseAxis;

    _currentRotation.y = Mathf.Clamp(_currentRotation.y, 90, -90);

    transform.localPosition += (Vector3)mouseAxis * weaponSwayAmount / 1000;
}

void DetermineAim()
{
    Vector3 target = normalLocalPosition;
    if (Input.GetMouseButton(1)) target = aimingLocalPosition;

    Vector3 desiredPosition = Vector3.Lerp(transform.localPosition, target, Time.deltaTime * aimSmoothing);

    transform.localPosition = desiredPosition;
}

void DetermineRecoil()
{
    transform.localPosition -= Vector3.forward * 0.2f;

    if (randomizeRecoil)
    {
        float xRecoil = Random.Range(-randomRecoilConstraints.x, randomRecoilConstraints.x);
        float yRecoil = Random.Range(-randomRecoilConstraints.y, randomRecoilConstraints.y);

        Vector2 recoil = new Vector2(xRecoil, yRecoil);

        _currentRotation += recoil;
    }
}
public IEnumerator shootGun()
{
    DetermineRecoil();
    RayCastForEnemy();
    StartCoroutine(MuzzleFlash());
    yield return new WaitForSeconds(fireRate);
    _canShoot = true;
}
public IEnumerator MuzzleFlash()
{
    muzzleFlashImage.sprite = flashes[Random.Range(0, flashes.Length)];
    muzzleFlashImage.color = Color.white;
    yield return new WaitForSeconds(0.05f);
    muzzleFlashImage.sprite = null;
    muzzleFlashImage.color = new Color(0, 0, 0, 0);
}

}

Your raycast should be coming from your camera, I cant tell properly but it looks like your raycast is coming from your player (not sure what transform.parent is). if its coming from your player then transform.forward will always be just forwards, you need to change it so the raycast comes from the players head/camera,

try something like:

if(Physics.Raycast(camera.transform.position, camera.transform.forward, out hit , 1 << LayerMask.NameToLayer(“Enemy”)))