Limiting in-air jumps

I am creating a platformer and managed to make my player jump while in the air. How do I limit this to a maximum of one air jump and nullify further “jump” inputs?

Here is the script I currently have:

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 40.0;

private var moveDirection : Vector3 = Vector3.zero;


function Update ()
{
	var controller : CharacterController = GetComponent( CharacterController );
	
	if ( controller.isGrounded)
	{
		moveDirection = Vector3 ( Input.GetAxis ( "Horizontal" ), 0, 0 );
		moveDirection = transform.TransformDirection ( moveDirection );
		moveDirection *= speed;
		
		if ( Input.GetButtonDown ( "Jump" ) )
		
	{
		moveDirection.y = jumpSpeed +20;
	}

}
if ( !controller.isGrounded )


{
	if (Input.GetButtonDown ("Jump") )
	
	{
	
		moveDirection.y = jumpSpeed +20;
	}
	moveDirection.x = Input.GetAxis ( "Horizontal" );
	moveDirection.x *= speed;
}
	
	moveDirection.y -= gravity * Time.deltaTime;
	controller.Move ( moveDirection * Time.deltaTime );
}

first move your getComponent character controller out of update. Everybody says to do it in function Start() however when I do this it gives me an error so just put it in the beginning with speed, jumpSpeed, gravity and moveDirection. Also make a private var: boolean and name it canDoubleJump or whatever. Now this next part is important

function Update(){
if(!controller.isGrounded && canDoubleJump && Input.GetButtonDown("Jump"))
{
     //Your air jump code
     canDoubleJump = false;// This is important now he can only jump ONCE!! because the **if statement** running this double jump no longer meets the requirements

     //The rest of your code

     if(controller.isGrounded && Input.GetButtonDown("Jump"))
{

moveDirection.y = jumpSpeed + 20// Not sure why you have +20(if what you're going for is for the first jump to go higher than the second jump then make another variable airJumpSpeed and assign that variable to your air jump code, that way you can tweak them in the inspector)
canDoubleJump = true;

}  
}

the airjump needs to be on top of the ground jump and I’ll tell you why. Unity is reading all of this in one frame. By moving the air jump on top of the ground jump you can ensure that Unity will read it after the frame where you ground jump. I’m going to go ahead and assume that you character jumps immediately after you jump off the ground and if so it is because it’s still the same frame & the same method, that is “Jump” is still being pressed in that frame so you press “Jump” when your grounded and you jump, suddenly in the same frame you are no longer grounded so **!**controller.isGrounded is suddenly true in that same frame and now you jump again and again and again because you dont have a way to turn it off. So like I said by moving airJump on top of groundJump you ensure that it happens on the new frame and that you have to press “Jump” again while in the air. I may be wrong about this lol haven’t tested sometimes I write from the wiiU but if you need any help understanding this better let me know. All credit goes to Coderdood who helped who helped me understand this. Lastly if my answer is correct please mark it as correct and give me a vote up never had a right answer before.