I tried that but I can't wrap my head around how I'm suppose to put it in this code. This isn't code I wrote btw, I'm trying to build on top of it and make mobile touch controls.
This is what I have in update:
//physical button jump
if (Input.GetButtonDown("Jump")){ //add touch to hold down here?
StartJump();
}
if (Input.GetTouch(0).phase == TouchPhase.Began){
StartJump();
}
This is Fixed Update which runs how high the player goes based on how long the button was pressed:
// If you need to hold the Jump input to jump higher...
if (jumpType == JumpType.HoldToJumpHigher) {
// When there is an initial jump...
if (initialJump) {
// ... set the y velocity to the player's initial jump value.
float yVel = jumpFactor * (doubleJump ? holdToJumpHigher.initialDoubleJump : holdToJumpHigher.initialJump);
And this is the start jump function:
void StartJump(){
// If the jump button is pressed, jumps are allowed and the player is not dashing, sliding, on a ladder or crouching under an obstacle...
if (!jump && jumps > 0 && !player.dashing && !player.sliding && !player.onLadder && (!player.crouching || (player.crouching && player.AllowedToStandUp()))) {
// If the player is grounded...
if (player.grounded) {
// ... initialize jump.
InitJump();
// If the player is not grounded and totalJumps is higher than 1...
} else if(doubleJumping.totalJumps > 1) {
// ... initialize jump if the Y velocity is inside the double jump window (or when there isn't a window).
if (!doubleJumping.jumpWindow || (doubleJumping.jumpWindow && rigidbody2D.velocity.y > doubleJumping.jumpWindowMin && rigidbody2D.velocity.y < doubleJumping.jumpWindowMax)) {
doubleJump = true;
InitJump();
}
}
}
}
I think what I have to do is figure out how to make the fixedupdate function into its own seperate function then in update call "if touchphase.stationary call holdtojumphigher();"
Problem is that the variable created in that fixedupdate is used in the rest of fixed update.
↧