title: Setting a rate of fire for a weapon - Unity
body: <p>I have only just started trying to develop a game in Unity and only have about 7 months of coding experience, so any help would be appreciated.</p>
  <p>As the title says, I am trying to set a rate of fire for a weapon in this game and here is my code.</p>
  <pre><code>{
      [SerializeField]
      private GameObject _arrowPrefab;
      [SerializeField]
      private float _fireRate = 1f;
      [SerializeField]
      private bool allowFire = false;
  
  
      // Start is called before the first frame update
      void Start()
      {
          
      }
  
      // Update is called once per frame
      void Update()
      {
          fireArrow(); 
      }
  
      public void fireArrow()
      {
          if (Input.GetMouseButton(0) &amp;&amp; allowFire)
          {
              StartCoroutine(FireRate());
          }
  
          IEnumerator FireRate()
          {
              allowFire = false;
              Instantiate(_arrowPrefab, transform.position, Quaternion.identity);
              yield return new WaitForSeconds(_fireRate);
              allowFire = true;
          }
      }
  
  
  }
  </code></pre>
  <p>So if I run the code as is, the weapon doesn't fire. If I check the allowFire box in the Unity engine and set the boolean to true, it fires as intended in one second intervals. But if I go back into the code and set the boolean to true initially, the weapon doesn't fire.</p>
  <p>I am assuming it is something small that I am missing but my searches have only resulted in me finding code that looks exactly like mine.</p>