IEnumerator FillExpBar() { currentAnimationTime = 0; float startExp = totalExp.value - gainedExp.value; float endExp = totalExp.value; ExpLevel expLevel = new ExpLevel((int)startExp); float filled = expLevel.PercentToNext(); valueImage.fillAmount = filled; yield return(new WaitForSeconds(startDelay)); float value = startExp; float currentDelay = sfxDelayTime; do { currentAnimationTime += Time.deltaTime / animationDuration; value = Mathf.Lerp(startExp, endExp, currentAnimationTime); bool levelUp = expLevel.SetExp((int)value); valueImage.fillAmount = expLevel.PercentToNext(); currentDelay += Time.deltaTime / animationDuration; if (levelUp) { levelupText.SetActive(true); valueImage.color = levelupColor; valueImage.fillAmount = 1; currentSfx.value.Enqueue(levelupSfx.clip); playSfxEvent.Invoke(); yield return(new WaitForSeconds(1)); valueImage.fillAmount = 0; valueImage.color = normalColor; levelupText.SetActive(false); } else if (currentDelay > sfxDelayTime) { currentSfx.value.Enqueue(gainExpSfx.clip); currentDelay = 0; playSfxEvent.Invoke(); } yield return(null); } while (value < endExp); yield break; }
IEnumerator FillExpBar() { currentAnimationTime = 0; float startExp = totalExp.value - gainedExp.value; float endExp = totalExp.value; ExpLevel expLevel = new ExpLevel((int)startExp); float filled = expLevel.PercentToNext(); valueImage.fillAmount = filled; Debug.Log("Filled is now: " + filled); Debug.Log("Waiting for start delay"); yield return(new WaitForSeconds(startDelay)); float value = startExp; do { currentAnimationTime += Time.deltaTime / animationDuration; value = Mathf.Lerp(startExp, endExp, currentAnimationTime); bool levelUp = expLevel.SetExp((int)value); valueImage.fillAmount = expLevel.PercentToNext(); // Debug.Log("Amount is now: " + value); if (levelUp) { // Debug.Log("#######Levelup!"); valueImage.color = levelupColor; valueImage.fillAmount = 1; yield return(new WaitForSeconds(1)); valueImage.fillAmount = 0; valueImage.color = normalColor; } yield return(null); } while (value < endExp); yield break; }