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(moveDirTime.deltaTime); // and finally move the character
}