Hello. I was aware of the issue with floating point imprecision prior to this lesson, but I’m glad Sam covered it. However, we’ve used tests for a float == 0 before, without mention. Specifically, in the Health.cs file, we have…
public void TakeDamage(GameObject instigator, float damage)
{
healthPoints.value = Mathf.Max(healthPoints.value - damage, 0);
if (healthPoints.value == 0)
{
Die();
AwardExperience(instigator);
}
else
{
takeDamage.Invoke(damage);
}
}
healthPoints is a LazyValue, but it was previously a normal float. Why is it safe to check the float healthPoints or healthPoints.value for equality with 0?