I’m trying to create a linear fall off but can’t seem to get it to work. I either end up with a smoothed fall off or an instant one. This is for updating a health bar so it looks like health is draining away.
What I’m currently trying is
// Use this for initialization
void Start () {
fgBar = transform.FindChild("HealthBarFG").gameObject;
startTime = Time.time;
}
// Update is called once per frame
void LateUpdate () {
float hp = ((float)pState.Health)/((float)pState.MaxHealth);
float tarHp = Mathf.Lerp(1, hp, (Time.time - startTime) * HealthSpeed);
fgBar.renderer.material.SetFloat("_Progress", tarHp);
}
But this causes tarHP to instantly jump to hp’s value. I’ve tried all sorts of values for HealthSpeed, though I’m currently using 1. What am I missing here?