I have the following script for animating my player. But i am very new to scripting and am not sure how to add something in there to play the animation for when he walks backwards.
here is the script -
function Update ()
{
if (Input.GetAxis("Vertical") > 0.2)
animation.CrossFade ("WALK");
else
animation.CrossFade ("IDLE");
}
can anyone help me figure out how to play the walking backwards animation, when the backwards key is pressed?
When you sayif(Input.GetAxis("Vertical") > 0.2)you are really telling the machine that when the x-axis input, left vs. right arrow, is more than 0.2 towards right, it should do stuff.
so in order to tell it to play an animation when walking towards left, you simply have to sayif(Input.GetAxis("Vertical") < -0.2)
so your resulting code would look something like this:
(also i put in curly braces { }, i would argue that it’s a good habbit to use those regardless of the ammount of commands inside the if-condition, simply because it looks prettier and easier to read (to me), but feel free to do however you want to)