Mathf.Lerp crashing build?

Hi,

I am trying to lerp the value of an Image component’s fillAmount from it’s current slider value to its hard current health value.

healthBar.fillAmount = Mathf.Lerp(healthBar.fillAmount, (float)health.GetHealth()/(float)health.GetMaxHealth(), Time.deltaTime * healthLerpSpeed);

I am running this in fixedUpdate() perfectly with no errors. The strange, unprecedented issue is that it always crashes my Android build when it reaches ~%50 health. I have no idea why. Anyone encounter this before?

FixedUpdate is for physics; you should be using Update. Also using Time.deltaTime directly in the third parameter of Lerp is not really correct usage and will result in slightly different results depending on framerate. In any case the exact code Unity uses for Lerp is

public static float Lerp (float a, float b, float t)
{
	return a + (b - a) * Mathf.Clamp01 (t);
}

There’s really no way that can crash anything. If the actual error has anything to do with the code you posted, perhaps GetMaxHealth returns 0 and you get a divide by zero error. Just a wild guess.