If I’m moving left or right, I can’t jump until the left/right keys are released. Once in the air I can move, however. Any help?
Here’s my code
var moveLeft: KeyCode;
var moveRight: KeyCode;
var jump: KeyCode;
var moveSpeed: float;
var jumpSpeed: float;
private var isFalling = false;
function Start () {
};
function Update () {
if (Input.GetKey(moveLeft)) {
rigidbody2D.velocity.x = moveSpeed *-1;
}
else if (Input.GetKey(moveRight)) {
rigidbody2D.velocity.x = moveSpeed;
}
else if (Input.GetKey(jump) && isFalling == false) {
rigidbody2D.velocity.y = jumpSpeed;
isFalling = true;
}
else {
rigidbody2D.velocity.x = 0;
};
};
function OnCollisionEnter2D() {
isFalling = false;
}