Hello !
I have to script a lean animation to my character. The script must do this:
If I only pressed ‘Q’ or ‘E’ and don’t hold it, the character switch his weapon from left to right (or right to left if ‘Q’ is pressed).
If I hold ‘Q’ or ‘E’ for the whole lean animation, I enter a lean “idle” state as long as I hold the key.
And when I release ‘Q’ or ‘E’ after a lean “idle” state, I go back to my standing state.
I guess it isn’t that hard to do, but it is the first time I’m using Unity to script character controllers so I’m a little lost and some help would be greatly appreciated 
Thanks for your time !
This should be fairly straightforward to code, but perhaps you could clarify the following. If you press and hold (for example) the Q key, is the character supposed to switch what they’re holding to their left hand and also lean left? Or is the ‘switch’ only supposed to occur if you press and release the Q key quickly, while if you hold the key, the switch doesn’t occur but the lean does?
Yeah if your gun is in the left hand and you lean right, the gun needs to switch hands. And if you release the lean key, you go back to “idle” with the gun in the right hand now.
It seems like this would be pretty straightforward: just start leaning when the key is pressed, and stop when it’s released. When you stop leaning, you would return to upright from wherever you were at that point in the ‘lean’ animation, so if you only pressed the key briefly, you’d just lean a little bit and then return to upright.
If you want a brief press of the key to switch hands without any leaning, then you could just add a brief delay between when the key is first pressed and when the ‘lean’ animation commences. If the key is down for a short time (shorter than the delay), the ‘switch’ would occur but there’d be no leaning.