I don’t know for sure but shouldn’t the crouch animation be on a higher layer than the other animations? Look in the manual on how to do it because I am on a school computer and can’t access it at the moment… good luck!
ok, i have put the crouch animation on the highest layer and it plays perfectly when i press the ‘c’ button.
however, i want to be able to walk using the ‘w’ key and crouch at the same time, as it is now i have to let go of the walk key and then press the crouch key.
here is the script -
animation["CROUCH"].layer=1;
function Update ()
{
if (Input.GetAxis("Vertical") > 0.2){
animation.CrossFade ("WALK");
}else if(Input.GetAxis("Vertical") < -0.2){
animation.CrossFade ("REVERSE");
// Play animation backwards when running backwards
animation["REVERSE"].speed = Mathf.Sign(Input.GetAxis("Vertical"));
}else if(Input.GetKeyDown("c")){
animation.CrossFade ("CROUCH");
}else{
animation.CrossFade ("IDLE");
}
}
I would change GetKeyDown to just GetKey - GetKeyDown only returns true on the frame that the button was pressed, but returns false on all frames after that until the button is pressed again. GetKey will (I think) return true while the button is down, and false when the button is up.
As it is now, your script fades into the crouch animation for a single frame, and then immediately back int the idle animation.
My tests yesterday show that only one key press at a time will register. The workaround is to store the keypress as a boolean and make a conditional that is both keys have been booleaned to true then do both animations at the same time. The next trick is unregistering the bool according to the key not being pressed and whether you want the crouch to take over, the idle or walk when the yadda yadda key is unpressed versus the bing bang key being pressed., etc…etc…etc. Other than that kind of workaround you are stuck with the one key being registered at a time paradigm.
One key registering at a time sounds to me more like a limitation of your controller/keyboard, not necessarily of Unity. I have script that checks for GetKey(whatever) with a bunch of different things, and I can certainly check if two keys are held down simultaneously.