how do i enable jumping when space is held down

hi. i have a 2d jumping game that I’m making for Android and IOS. but how do i change my script so that the player jumps when space is held down? (I know that on android/IOS there isn’t a space button but I’ll change that later.)

Here’s my script:

var speed: float = 2; // move speed

var jumpSpeed: float = 12; // initial jump speed
var gravity: float = 30;

private var cc: CharacterController;
private var vSpeed: float;

function Update(){

var moveDir = Vector3.right * speed; // calculate the horizontal speed

if (!cc) cc = GetComponent(CharacterController); // get the CharacterController
if (cc.isGrounded){ // when grounded...

	vSpeed = 0.0;  // vSpeed is zero...

if (Input.GetButtonDown("Jump")){ // unless the character jumps
	
	vSpeed = jumpSpeed; 

}
}

vSpeed -= gravityTime.deltaTime; // apply a physically correct gravity
moveDir.y = vSpeed; // add the vertical speed
cc.Move(moveDir
Time.deltaTime); // and finally move the character

}

I don’t quite know what exactly you mean with “jump when space is held down” but whatever it might be exactly, I think that using "Input.GetButton(“Jump”) would be appropriate,

Input.GetButtonDown(“Jump”) only fires once (returns true once) - when the player presses the button down. If it is held the whole time you wouldn’t know. Input.GetButton(“Jump”) on the other hand returns true as long the button is down. That way you might be able to accomplish whatever behavior you are intending to implement.

Hope that helps,

delstrega

u can check grouded then when grounded jumping equal to false and when press Jump Button and Not Grounded The Jumping = true