Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to stop an animation with mecanim

Discussion in 'Animation' started by TheCrowXD, Jan 27, 2014.

  1. TheCrowXD

    TheCrowXD

    Joined:
    Jan 24, 2014
    Posts:
    5
    i was using animation and i had this on my code:
    Code (csharp):
    1. animation.Stop("attack");
    but it doesnt work with animator. i have checked every post about this but i cant find a right answer and i can t believe that there isnt a function to do something so basic.

    for example: my hero is casting a spell but is countered so i want to stop the "casting spell" animation.

    how can i cancel the current animation with animator/mecanim?
     
  2. makoto_snkw

    makoto_snkw

    Joined:
    Aug 14, 2013
    Posts:
    340
    Mecanim is using parameter.

    For example, From Idle state to Walk, the parameter value for the transition to happen is 0.1 - 1.

    So when the parameter value is more than 0.1, mecanim will trigger the "WALK" animation.
    To stop the WALK animation, simple reset the parameter to less than 0.1.

    For your case, perhaps.

    Idle <==> Casting Spell.

    You can use boolean parameter, castSPell = false.

    So when you press a key, a function will be triggered to change the parameter of castSpell = true.

    So it will animate Casting Spell.

    I highly recommend you to download Unity Sample Assets (Beta) from the Asset Store and see how the mecanim and Third Person Control script shows how to change from idle to crouch, etc.

    But you have to reset back to false so the animation goes back to Idle.