//Fades the time scale with a custom lerp private IEnumerator CustomLerp(LerpObject lerpObject) { float startingValue = lerpObject.lerpedVariableGetter(); float valueDistance = lerpObject.targetValue - lerpObject.lerpedVariableGetter(); float startingLerpTime = Time.realtimeSinceStartup; float endingLerpTime = Time.realtimeSinceStartup + lerpObject.lerpDuration; while (lerpObject.instanceId == lerpObject.currentIdGetter() && Time.realtimeSinceStartup <= endingLerpTime) { float currentLerpTime = (Time.realtimeSinceStartup - startingLerpTime); float lerpedPosition = lerpObject.lerpFunction(currentLerpTime, lerpObject.lerpDuration); lerpObject.lerpedVariableSetter((valueDistance * lerpedPosition) + startingValue); yield return(new WaitForSecondsRealtime(coroutineUpdateFrequency)); } yield return(null); if (lerpObject.instanceId == lerpObject.currentIdGetter()) { lerpObject.lerpedVariableSetter(lerpObject.targetValue); if (lerpObject.onFinishEvent != null) { lerpObject.onFinishEvent.Invoke(); } if (lerpObject.onFinishFunction != null) { lerpObject.onFinishFunction(); } } }