private IEnumerator SlowRoutine() { slowRoutine = true; while (slowEffect.Count > 0) { float targetVal = 1.0f; for (int i = 0; i < slowEffect.Count; i++) { Slow slow = slowEffect[i]; //check if the effect has expired if (Time.time >= slow.GetTimeEnd()) { slowEffect.RemoveAt(i); i--; } //if the effect is not expire, check the slowFactor //record the val if the slowFactor is slower than the previous entry else if (1 - slow.slowFactor < targetVal) { targetVal = 1 - slow.slowFactor; targetVal = Mathf.Max(0, targetVal); } } slowModifier = Mathf.Lerp(slowModifier, targetVal, Time.deltaTime * 10); if (subClass == _UnitSubClass.Creep) { unitC.UpdateMoveAnimationSpeed(); } yield return(null); } slowRoutine = false; while (slowEffect.Count == 0) { slowModifier = Mathf.Lerp(slowModifier, 1, Time.deltaTime * 10); if (subClass == _UnitSubClass.Creep) { unitC.UpdateMoveAnimationSpeed(); } yield return(null); } if (subClass == _UnitSubClass.Creep) { unitC.UpdateMoveAnimationSpeed(); } }