Reputation: 3
I have a character that can jump and also crouch with this:
if ((Input.GetButtonDown("Jump")))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
runSpeed = 0f;
}else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
runSpeed = 20f;
}
My character has a fairly large hitbox and when he crouches the hitbox gets considerably smaller. My issue: While the character is jumping if they crouch the hitbox will get smaller while they are in the air, i want to avoid that by checking that while jump is true and the user presses the button "crouch" the character won't crouch. But because my ifs are inside the Update method i can't use while because i create an infinite loop.I tried using a double check like:
if jump and crouch then no crouch
if no jump and crouch then crouch
But that doesnt work either. My idea was to use while loops but i can't so how can i create something that can check that while my jump is true then i can't crouch. (i have a function that does ground check so my jump will turn to false as soon as the character hits the floor)
thank you
update-this is not a case of &
or &&
, thank you
Upvotes: 0
Views: 432
Reputation: 1712
if ((Input.GetButtonDown("Jump")))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
if(!animator.GetBool("IsJumping")){
crouch = true;
runSpeed = 0f;
}
}else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
runSpeed = 20f;
}
note in particular, this
if(!animator.GetBool("IsJumping")){
crouch = true;
runSpeed = 0f;
}
in the middle statement
Upvotes: 2