- Home /
 
 
               Question by 
               konradryczko1 · Feb 24, 2019 at 11:10 AM · 
                loopfor-looptime.deltatime  
              
 
              for loop problem,problem with for loop
Hello, ihave no idea why this loop is performed only once. please help, many thanks
 if (sc.wykorzystana == false)
     {
         secondcha.SetActive(true);
         for (float timer = 5; timer >= 0; timer -= Time.deltaTime)
         {                           
             if (sc.szansa ==1)
             {
                                                                               
                 yield break;
             }
             Debug.Log(timer);
             yield return null;
            
         }
 
               pleas help me, many thanks.
               Comment
              
 
               
              $$anonymous$$ake sure this is in a IEnumerator method and that you are calling within StartCoroutine();
Answer by bpaynom · Feb 24, 2019 at 02:05 PM
Looks like sc.szansa is 1, so it breaks the coroutine. yield break doesnt break the inner loop. Breaks the coroutine. Try this:
 if (sc.wykorzystana == false)
 {
     secondcha.SetActive(true);
     for (float timer = 5; timer >= 0; timer -= Time.deltaTime)
     {                           
           if (sc.szansa ==1)
           {
                  timer = 0;
           }else{
                  Debug.Log(timer);
                  yield return null;
           }
       }
 }
 
              Your answer