I am attempting to give my player a double jump in my 2D game. All the stuff that is in comment form in the script is what I attempted to use to perform my double jump.
void StateInAir()
{
HandleHorizontalInput ();
if (canJump) {
if (timeHoldingInput < maxJumpBtnHoldTime && Input.GetKey(KeyCode.Space))
{
timeHoldingInput += Time.deltaTime;
GetComponent<Rigidbody2D> ().velocity += new Vector2 (0, thePlayer.JumpAccel ());
// if(Input.GetKeyUp(KeyCode.Space) && doublejump == true)
// {
// SetState(PlayerStates.ENTER_JUMP);
// if (timeHoldingInput < maxJumpBtnHoldTime && Input.GetKey (KeyCode.Space))
// {
// timeHoldingInput += Time.deltaTime;
// GetComponent<Rigidbody2D> ().velocity += new Vector2 (0, thePlayer.JumpAccel ());
// doublejump = false;
// }
// }
}
// else if( doublejump == true)
// {
// timeHoldingInput = 0;
// doublejump = false;
// }
else
{
canJump = false;
//SetState(PlayerStates.IDLE);
}
}
else
{
CheckForGround();
if( onGround)
{
HandleLandOnGround();
doublejump = true;
}
}
}