animation - Unity 5.1 Animator Controller not transitioning -
i have created animator controller
(called player
) , assigned animator
field of humanoid avatar, simple animation states suitable transitions. please see 2 attached images.
i have attached script, containing following code, avatar game object, wonder missing or doing wrong transition idle
walk
not take place, though can see speed
variable increases when press w
.
could please me understand problem?
using unityengine; using system.collections; public class charanim : monobehaviour { private animator animator; float speed; void start() { animator = getcomponent<animator>(); } void update() { animator.setfloat( "speed", input.getaxis("vertical") ); if ( input.getkeydown( keycode.w ) && ( speed > 0.5f ) ) { animator.settrigger("walk"); } else { animator.settrigger("idle"); } } }
x
the problem in code is, animator.settrigger("walk");
gets called in single frame when pressed key , animator.settrigger("idle");
gets called rest of frames.
try changing input.getkeydown( keycode.w )
input.getkey( keycode.w )
. former returns true once, instant when press down key, whereas latter returns true until release key. :
void update () { if(input.getkey(keycode.w)) { animator.settrigger("walk"); } else animator.settrigger("idle"); }
on side note, don't need speed
variable in animator
trigger walk animation, since doing using w
.
Comments
Post a Comment