Hello, I’m trying to make an exp bar scale smoothly using lerp. When the player gains exp though the bar scales instantly even though I’m using lerp.
Here is a gif of the bar and the script
https://gyazo.com/13f94f3642f736cfe2908462b1f0b17d
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Exp : MonoBehaviour
{
//Stats
public float minExp;
public float maxExp;
public float exp;
private float minWidth = 250;
private float maxWidth = 1509;
private float width;
[SerializeField]
private float lerpSpeed;
//Components
public RectTransform bar;
void Start()
{
UpdateBar();
}
public void UpdateBar()
{
exp = Mathf.Clamp(exp, minExp, maxExp);
width = (exp / maxExp) * (maxWidth - minWidth) + minWidth;
bar.sizeDelta = Vector2.Lerp(bar.sizeDelta, new Vector2(width, bar.sizeDelta.y), lerpSpeed);
}
}