animation layers

I have four animations for player,run,idle battle,die and attack.To avoid animation mixing I put die animation on layer 2 and attack on 1…but player keeps on running.he doesn’t attack as i want when distance of player is less than 2 from enemy he should attack…but it doesn’t work well

why r u putting in layers,
i don’t know but in the animation component
there is a option called size
mention the size u want and then assign the animations
then call in the code

16857-anim.jpg

Your ifs are wrong. The part that plays attack never runs.

The first if checks for less than 20, so the else-if less than 2 is always false. Maybe change the order: greater than 20 idle, greater than 2 run, else (attack.)

Also, as (I think?) yogee writes, you don’t need layers for this, since you explicitly play each one. Layers are for something like: when attack stops by itself, run/idle automatically resumes Or for mixing partial animations.