-1

I need to pause some code in an if statement in c#. Thread.Sleep() is NOT what I want as it pauses everything. I just want to temporarily hold the code in an if statement where it is for a few seconds.

I have tried Thread.Sleep() but it is not what I want.

This is in my Update() method.

if (jumps == jumpsToFatigue)
    {
        // wait for jumpFatigueWait (variable that is in seconds)
        jumps = 0f;
    }

I want something that can replace the comment that will pause THIS if statement ONLY for the time specified in my variable.

Fin Harris
  • 35
  • 1
  • 4

1 Answers1

0

Sorry cant test now but you can try,Edited

   IEnumerator WaitForYourSecond()
    {
      yield return new WaitForSeconds(2f);
      jump = 0;
    }
    void Update()
    {
    if (jumps == jumpsToFatigue)
        {
           StartCoroutine("WaitForYourSecond");

        }
    }
auslander
  • 470
  • 5
  • 17
  • You'll probably want another check for if the coroutine is already running, or hitting the fatigue limit will let you spam the control and get as many jumps as you want for 2 seconds after the cooldown expires. – Draco18s no longer trusts SE Oct 24 '19 at 14:16