I trigger the following UnityScript function once when my game pauses (timeScale zero).
function animatePie( pieStart : float, pieEnd : float ) {
for (var f = pieStart; f >= pieEnd; f -= .0333) {
upgradePie.GetComponent(UnityEngine.UI.Image).fillAmount = f;
Debug.Log("TEST");
yield WaitForSeconds(.0333);
}
}
But for some reason it runs only once: “TEST” is only output a single time. It doesn’t seem to matter what value I put in WaitForSeconds, the loop never cycles.
However, if I take out the WaitForSeconds and use yield alone, all is well: “TEST” outputs multiple times (and the fillAmount animates nicely).
But yield alone doesn’t give me control over the speed of the animation, so it will vary per device. (Nor can I handle that with Time.deltaTime, since the game is paused.)
Why would yield fail to execute when I use WaitForSeconds?
Thanks for any help recognizing my mental block!