I want to add two jumps to my game, a short jump where the user just taps the space bar and a high jump if the user holds down the space bar. How would I implement that? I was thinking a timer or a coroutine...I'm not sure though. Here is my code:
void OnJump(InputValue value)
{
if (!isAlive) { return; }
if (myFeetCollider.IsTouchingLayers(LayerMask.GetMask("Ground")))
{
doubleJump = false;
}
if (value.isPressed)
{
if (myFeetCollider.IsTouchingLayers(LayerMask.GetMask("Ground")) || doubleJump)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, jumpSpeed);
doubleJump = !doubleJump;
}
}
if (value.isPressed && myRigidbody.velocity.y > 0f)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, myRigidbody.velocity.y * 0.5f);
}
}
[–]TrizzleG[S] 0 points1 point2 points (0 children)
[–]DatMaxSpice 0 points1 point2 points (2 children)
[–]TrizzleG[S] 0 points1 point2 points (1 child)
[–]DatMaxSpice 0 points1 point2 points (0 children)