Something very weird is going on, I’m trying to check if a float called fireDelay is lower than 0. Which, according to what I programmed, it is. But it seems that it doesn’t work.
I made a boolean check that writes in the Debug.Log, and the actual float value that writes in the debug log.
public float fireDelay = 0.0f;
public void PrimaryFire(RaycastHit hit)
{
bool fireDelayLower = fireDelay <= 0.0f;
Debug.Log("fireDelayLower = " + fireDelayLower);
Debug.Log(fireDelay);
if (fireDelay <= 0.0f)
{
Debug.Log(pickupOwner.GetComponent<AudioSource>(), pickupOwner);
this.fireDelay = fireRate;
pickupOwner.GetComponent<AudioSource>().PlayOneShot(gunSound[Random.Range(0, gunSound.Length - 1)]);
}
if (currentClip <= 0)
{
DryFire();
return;
}
}
Output:
fireDelayLower = False
0.3
And in the inspector itself…
I understand that it’s -0.02etc because of the floating point error. But shouldn’t it be -0.00000001 instead?
What exactly is going on here and how do I fix it?