I created a character with animations, walking from frame 1 to 60 and resting from frame 61 to 62. Then I have applied the following code but it doesn’t work.
function Update ()
{
if (Input.GetAxis("Vertical") > 0.2)
animation.CrossFade ("idle");
else
animation.CrossFade ("walk");
}
Uh… If you want your character to perform the walk animation when you press the “vertical” keys, shouldn’t your if statement say:
function Update ()
{
if (Input.GetAxis("Vertical") > 0.2)
animation.CrossFade ("walk");
else
animation.CrossFade ("idle");
}
(BTW, I use this code for my walk/run sequence)
if (Mathf.Abs(Input.GetAxis("Vertical")) > (0.2*(.5*scale)))
animation.CrossFade("walk");
//scale is my own variable for when I implement different scales for my character
Also did you initialize your animations in the Start function?
How about putting your animation “idle” as element 0 for your animations and walk as element 1 for your animations.
Animation tab → Element 0 = walk atm (word of advice, idle should always be your first animation)
Also double check that idle is spelt the same in all scripts (no “Idle” and “idle” it’s case sensitive) Also have this instead for start:
Ok, I put walk as element 1 and idle (well spelt) as element 0. Then I put idle as the object of Animation (see the video) in the Player and in the Character. Now plays idle when start but it doesn’t walk.
Ok, that means we’re getting somewhere. Now, for your walking, is that controller relating itself to “Vertical”? Like if you were to push the WASD or arrow keys? If not then your problem is stemming from there (meaning vertical isn’t being used when you’re calling an if statement for it), second, use Mathf.Abs instead:
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
animation.CrossFade("walk");
Start with the WASD/arrow keys, and then work your way towards that left joystick’s movement, I think you jumped too far ahead making that joystick. Also if your animations with with WASD/arrow keys, it means that your joystick is having the problem and not your animation script.