Search Unity

Reload clip in update with courutine

Discussion in 'Scripting' started by hrohibil, Jan 14, 2022.

  1. hrohibil

    hrohibil

    Joined:
    Apr 17, 2021
    Posts:
    280
    Hello

    I have a input get key down in a if statement in the update method.

    when I press the R key and my bullet count equals to zero it fires a courutine and I can reload.
    This works exactly as expected .

    now I try to do this automatically without pressing the R key so in my update function I have an if statement if bullet count is zero then do exactly as before, but I think do to the nature of update every frame this does not work.
    It does it several time. How can I execute same setup in the update ? I tried fixed update with same result.
    I think I maybe need a bool to check for once??
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Either store the return value of StartCoroutine and use that to keep track, or yeah, use an isReloading boolean.