I want to smoothly go from one value to a new one (moving a slider or changing color). I tried using both functions and they all basically give the same result. What is the difference between them and which one should I use?
How I used SmoothDamp:
// Show the HUD
private IEnumerator ShowHUD() {
var HUDCanvasGroup = GameObject.FindWithTag("HUD").GetComponent<CanvasGroup>();
var alphaValue = 1f;
var velocity = 0f;
var time = 0.30f;
yield return new WaitForSeconds(1.5f);
// Gradually fade in the canvas
while (!Mathf.Approximately(HUDCanvasGroup.alpha, alphaValue)) {
HUDCanvasGroup.alpha = Mathf.SmoothDamp(HUDCanvasGroup.alpha, alphaValue, ref velocity, time);
yield return null;
}
HUDCanvasGroup.alpha = 1; // Since float is not accurate, manually set the alpha to 1 after
HUDCanvasGroup.interactable = true;
var blur = GameObject.FindWithTag("BlurryCamera").GetComponent<BlurOptimized>();
blur.enabled = true;
}
How I used Lerp:
public static IEnumerator Dim() {
while (t < 1) {
t += Time.deltaTime / 0.4f;
dimRend.material.color = Color.Lerp(undimColor, dimColor, t);
yield return null;
}
}
Color.Lerp
that interpolates between color instead of values \$\endgroup\$