I'm having difficulties making the player aim with a controller

So I have set up a jump and move input functions but the player aiming is hard. I’ve spent more than an hour trying to solve this but I can’t. I’m trying to make the player aim automatically at the enemy since I was having difficulties making it so he could free aim.
The crosshair works and stays on the enemy but the gun function doesn’t work somehow, any help would be appreciated.

public class PointAndShoot : MonoBehaviour
{
    public GameObject crosshairs;
    public GameObject player; //this is the gun of the player
    public GameObject bulletPrefab;
    public GameObject bulletStart;

    private Transform enemy;

    private float timeBtwShots;
    public float startTimeBtwShots;

    public GameObject muzzleFire;

    public float bulletSpeed = 20.0f;

    private Vector3 target;
    private Transform TARGET;
    public GameObject[] TTarget;
    public float range = 10f;

    float nextTimeToSearch = 0;

    [Header("Audio")]
    public AudioClip pistolSound;

    void Start()
    {
        Cursor.visible = false;

        timeBtwShots = startTimeBtwShots;

        InvokeRepeating("UpdateTarget", 0f, 0.01f);

        enemy = GameObject.FindGameObjectWithTag("Enemy").transform;
    }


    void UpdateTarget()
    {
        GameObject[] enemies = GameObject.FindGameObjectsWithTag("Enemy");
        float shortestDistance = Mathf.Infinity;
        GameObject nearestEnemy = null;

        target = transform.GetComponent<Camera>().ScreenToWorldPoint(new Vector2(crosshairs.transform.position.x, crosshairs.transform.position.y));
        TTarget = enemies;

        crosshairs.transform.position = new Vector2(gameObject.transform.position.x, gameObject.transform.position.y);

        foreach (GameObject enemy in enemies)
        {
            float distanceToEnemy = Vector3.Distance(transform.position, enemy.transform.position);
            if (distanceToEnemy < shortestDistance)
            {
                shortestDistance = distanceToEnemy;
                nearestEnemy = enemy;

                crosshairs.transform.position = nearestEnemy.transform.position;
            }
        }

        if(nearestEnemy != null && shortestDistance <= range)
        {
            TARGET = nearestEnemy.transform;
        }
        else
        {
            TARGET = null;
        }
    }


    public void Update()
    {
        if (TARGET == null)
            return;



        Vector3 difference = target - player.transform.position;
        float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
        player.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationZ);

        Vector3 aimLocalScale = Vector3.one;
        if (rotationZ > 90 || rotationZ < -90)
        {
            aimLocalScale.y = -1f;
        }
        else
        {
            aimLocalScale.y = +1f;
        }
        player.transform.localScale = aimLocalScale;

        float fire = Input.GetAxis("Fire1");

        if (timeBtwShots <= 0)
        {
            if (fire != 0f)
            {
                float distance = difference.magnitude;
                Vector2 direction = difference / distance;
                direction.Normalize();
                fireBullet(direction, rotationZ);

                timeBtwShots = startTimeBtwShots;

                AudioSource audio = GetComponent<AudioSource>();
                audio.PlayOneShot(pistolSound);
            }

        }
        else
        {
            timeBtwShots -= Time.deltaTime;
        }

        if (target == null)
        {
            Debug.Log("FindPlayer");
            FindPlayer();
            return;
        }

    }

    public void fireBullet(Vector2 direction, float rotationZ)
    {
        GameObject b = Instantiate(bulletPrefab) as GameObject;
        b.transform.position = bulletStart.transform.position;
        b.transform.rotation = Quaternion.Euler(0.0f, 0.0f, rotationZ);
        b.GetComponent<Rigidbody2D>().velocity = direction * bulletSpeed;
        PlayerBullet pBullet = b.GetComponent<PlayerBullet>();

        if (pBullet != null)
            pBullet.Seek(TARGET);
    }

    void FindPlayer()
    {
        if (nextTimeToSearch <= Time.time)
        {
            GameObject searchResult = GameObject.FindGameObjectWithTag("Player");
            if (searchResult != null)
                target = searchResult.transform.position;
            nextTimeToSearch = Time.time + 0.5f;
        }
    }

    void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(transform.position, range);
    }

}

This is the gun code, I’m not sure i need to also put the player controller script here so I’ll just post the gun one.
Thanks

Perhaps it would be easier to just make him aim freely with the controller stick? I tried that but it didn’t turn out so well, got some bugs.