How can you make a boolean return true ONLY on the frame the condition was completed

I have a player that I want only to jump on the frame that Input.GetAxis(“Vertical”) > 0.5f. Kind of like Input.GetButtonDown but with the condition being that the Vertical Axis is greater than 0.5f.

Create a boolean.

Set it to false.

When the condition is true, and it is false, set it to true and do the action.

When the condition is no longer true, set it to false again.

This is called an “edge condition” or “step function” in computer science.

How about something like this:

float prevVertAxis = 0.0;

function Update() {

    var axis = Input.GetAxis("Vertical");
    if (axis > 0.5 && prevVertAxis <= 0.5) {
        // Fire off whatever you want
    }
    prevVertAxis = axis;
}

I figured out how to make the jumping possible now, but it does not have to do with making a boolean true the frame a condition became true.I added another boolean that becomes true when the axis has reset or is greater than -0.1f or less than 0.1. it goes like this

void CheckCanJump()
	{
		if(controller.isGrounded)
		{
			jumps = 0;//set to 0 when player is grounded so player can jump twice;
			isJumping = false;
		}
		if(jumps < 2)//only jumps if the player has jumped less than 2 time since he hit the ground 
		{
			isAbleToJump = true;
		}
		else
		{
			isAbleToJump = false;
		}
		if(Input.GetAxisRaw("Vertical") > 0.5f && axisHasReset == true) 
		{									   
			axisHasReset = false;
			canJump = true;				   
		}
		else
		{
			canJump = false;
		}
		if(-0.1f < Input.GetAxisRaw("Vertical") && Input.GetAxisRaw("Vertical") < 0.1f)
		{
			axisHasReset = true;
		}
	}