Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Biggix on December 25, 2014, 06:44:43 PM

Title: UIProgressbar.value and Yield don't work together?!
Post by: Biggix on December 25, 2014, 06:44:43 PM
Another issue which is driving me crazy.

I'm using a very simple coroutine to update gradually a value of an UIProgressBar.

  1. var go = GameObject.Find ("ProgressBack");
  2. UIProgressBar uil = go.GetComponent<UIProgressBar> ();
  3. float add=0.01f;
  4. float st=0f;
  5.  
  6.         for (var h=1; h<=20; h+=1) {
  7.                        
  8.                         uil.value =st+(add*h);
  9.                        
  10.                         yield return new WaitForSeconds (0.05f);
  11.                        
  12.                 }

The same code is used to adjust the value of a money counter in another similar IENumerator so it works and it is not the issue of the code itself.

It's something with the UIProgressbar. When I put debug info, it's clear the "for" cycle is executed only once for some unknown reason (instead of 20 times).
Title: Re: UIProgressbar.value and Yield don't work together?!
Post by: ArenMook on December 30, 2014, 02:32:07 PM
How do you launch this coroutine? You need to explicitly start it. There are no issues updating a progress bar from a coroutine.
Title: Re: UIProgressbar.value and Yield don't work together?!
Post by: Biggix on December 30, 2014, 10:59:41 PM
I found out that it's not NGUI, it's some strange Unity behaviour. Under certain conditions, Unity stops a coroutine upon the very first yeild. I can't define a pattern on when this happens but I already encountered this twice. Had to do a workaround both times.
Title: Re: UIProgressbar.value and Yield don't work together?!
Post by: ArenMook on December 31, 2014, 03:57:45 PM
Oh yeah, I've ran into that obscure issue once too... if you can figure out what causes it to happen, I'd love to know.