New Input System for getting continuous input

I’m trying to do a continous shooting system, but as well when I press the button once it would only shoot once. And if a button is pressed in between attacks, when the attackDelay would end it would shoot again. I managed to do it, but it seems insufficient with four booleans. Maybe it’s possible to make it better? Would appreciate any help.

public class PlayerAttack : MonoBehaviour
{
    [SerializeField] private float PistolAttackDelay = .5f;
    [SerializeField] private GameObject Bullet;
    [SerializeField]  private Transform BulletSpawnPoint;
    private bool CanAttack = true;
    private bool isAttackHeld;
    private bool AttackPressed = false;
    private bool AttackReleased = false;
   //When left mouse button is pressed this method is called
    public void PistolAttack()
    {
        if (CanAttack)
        {
            isAttackHeld = true;
            StartCoroutine(ShootBullet());
        }
        // Else method is called when mouse is pressed between the attacks(when pistolAttackDelay 
        //   hasn't ended)
        else
        {
            AttackPressed = true;
            isAttackHeld = true;
        }
    }
    IEnumerator ShootBullet()
    {
        CanAttack = false;
        while (isAttackHeld)
        {
            Instantiate(Bullet, BulletSpawnPoint);
            yield return new WaitForSeconds(PistolAttackDelay);
            if (AttackReleased)
            {
                AttackReleased = false;
                break;
            }
        }
        if (AttackPressed)
        {
            AttackPressed = false;
            if (!isAttackHeld)
                AttackReleased = true;
            isAttackHeld = true;
            StartCoroutine(ShootBullet());
        }
        else
            CanAttack = true;
    }
    // When mouse button released this method is called
    public void CancelAttack()
    {
        isAttackHeld = false;
    }
}

Input.GetMouseButton(0) seems to be what you are looking for.
I’m not sure if this is the most efficient but this is some pseudocode of what I’d do:

    private bool attack = false;
    private bool isAttacking = false;
    
        void Update()
        {
            if (attack && !isAttacking)
            {
                 StartCoroutine(shoot)
                 isAttacking = true
            } else if (!attack && isAttacking)
            {
                  StopCoroutine(shoot)
                  isAttacking = false
            }
    
            if (Input.GetMouseButton(0))
            {
                attack = true;
            } 
            if(Input.GetMouseButtonUp(0))
            {
                attack = false;
            }
        }
    
    Ienumerator shoot() {
         Instantiate bullet
         yield return new waitforseconds(attackDelay);
    }

** I don’t believe that this works for your condition of “if a button is pressed in between attacks, when the attackDelay would end it would shoot again” since it stops fully when the mouse button is released and restarts fully when pressed again. Don’t forget to startcoroutine and stopcoroutine with string if you want the coroutine to be reset. I hope this helps.