Jump counter for double jump script not working? C#

It was working fine last night but it doesn’t work today, the zJumpCount stays at zero after I jump now. If the zJumpcount stays at zero my double jump code doesn’t work. I even ctrl+z’d back to the beginning of the session with no luck, plaez halp.

    public float zMoveSpeed;
    public float zJumpThrust;          
    public bool IsGrounded; 
    public float zJumpCount;
    private Rigidbody zRB;    

void Start () {
	zRB = GetComponent<Rigidbody>();
}

void Update () {

    if (IsGrounded == true) 
    {
        zJumpCount = 0.0f;
    }

    if (Input.GetKey(KeyCode.A))
    {
        zRB.transform.Translate(Vector3.left * zMoveSpeed);
    }

    if (Input.GetKey(KeyCode.D))
    {
        zRB.transform.Translate(Vector3.right * zMoveSpeed);
    }

	if(Input.GetButtonDown("Jump") && IsGrounded == true)
	{
		zRB.AddForce(Vector3.up * zJumpThrust, ForceMode.VelocityChange);
        zJumpCount++;
	}
    if (IsGrounded == false && zJumpCount > 0 && zJumpCount < 2)
    {
        if (Input.GetButtonDown("Jump"))
        {
            zRB.AddForce(Vector3.up * zJumpThrust, ForceMode.VelocityChange);
            zJumpCount++;
        }
        if (IsGrounded == false && zJumpCount >= 2)
        {
            if (Input.GetButtonDown("Jump"))
                return;
        }
    }


}
	
void OnCollisionStay (Collision collisionInfo)
{
	IsGrounded = true;
}

void OnCollisionExit (Collision collisionInfo)
{
	IsGrounded = false;
}

}

Your problem is most likely that you are only setting IsGrounded to false OnCollisionExit. that works fine if the physics steps are running synchronous to the frame update. But it rarely is.

Try setting IsGrounded to false as soon as you jump:

     if(Input.GetButtonDown("Jump") && IsGrounded == true)
     {
         zRB.AddForce(Vector3.up * zJumpThrust, ForceMode.VelocityChange);
         zJumpCount++;
         IsGrounded = false;
     }

In the beginning of your Update zJumpCount is set to 0 if you are still grounded, but in many cases OnCollisionExit will not be triggered right after you apply force. Remove code below and move it to your OnCollisionStay or FixedUpdate.

     if (IsGrounded == true) 
     {
         zJumpCount = 0.0f;
     }

Also zJumpCount should be an int, but that has nothing to do with your error.

Ths link might help understanding the physics steps in Unity FixedUpdate vs Update