- Home /
Crouching in 2D with 1 button
Hello,
I'm having trouble with making my 2D character crouch with 1 key input. Here's what I have so far...
if (Input.GetKeyDown (KeyCode.LeftControl)) {
anim.SetBool ("Crouch", !crouched);
}
if (Input.GetKeyDown (KeyCode.RightControl)) {
anim.SetBool ("Crouch", crouched);
}
"Crouch" is the parameter with an initial value of false. crouched is a boolean set to false.
This does work, if I press LeftControl the character crouches and if I press RightControl the character stands up again. What I need help with is how do I get it so that I press LeftControl the player crouches and then press the same key again to make him stand rather than having 2 keys to do the job.
Thanks for your help in advance.
Answer by Patel-Sagar · Jan 20, 2014 at 10:16 AM
if (Input.GetKeyDown (KeyCode.LeftControl)) { crouched = !crouched; anim.SetBool ("Crouch", crouched); }
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
2.5D Platformer - Jump Question 1 Answer
lighting click help 3 Answers
how to get void function in c# script to other c#script? 2 Answers
Accessing List from Parent G.O. Script 0 Answers