- Home /
Question by
bpears · Jan 05, 2013 at 09:26 PM ·
javascriptinputmanager
Keep crouched until button pressed again? Javascript provided
The script is set up, works great. The only thing is, when you press crouch button, you must hold it down. How can I make it so that you can toggle the crouch (Stay in crouch until button pressed again)?
I am using input manager.
if (Input.GetButtonDown("Crouch") && !crouching) {
collider.height = 1.5;
collider.center = Vector3 (0, -0.25, 0);
crouching = true;
}
if(Input.GetButtonUp("Crouch") && crouching){
collider.height = 2.0;
collider.center = Vector3 (0, 0, 0);
crouching = false;
}
Comment
Best Answer
Answer by Davidovich · Jan 05, 2013 at 09:52 PM
You just need to have the crouch and un-crouch functionality react to the button down, rather than the un-crouch being triggered when the button is released.
if (Input.GetButtonDown("Crouch")) {
if (!crouching) {
collider.height = 1.5;
collider.center = Vector3 (0, -0.25, 0);
crouching = true;
}
else {
collider.height = 2.0;
collider.center = Vector3 (0, 0, 0);
crouching = false;
}
}
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Cube terrain with perlin noise 1 Answer
Click To Revert to Original Texture else Destroy script help 1 Answer
What is wrong with this script? 2 Answers
How to Implement System.StringBuilder into JavaScript? 2 Answers