Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Preventing a animation from playing if a animation is active on the same asset.

Discussion in 'Animation' started by HyperTheSamurai, Apr 12, 2014.

  1. HyperTheSamurai

    HyperTheSamurai

    Joined:
    Mar 9, 2014
    Posts:
    2
    So for my melee system I want to be able to have the attack animation play while moving, however I have a animation that plays when the character walks, here is what I want to do.

    I want the walking animation to cancel and play the attack animation without it switching back to the walk animation until the attack animation finishes.


    I am using JavaScript so any help is appreciated.
     
  2. Andreapigna

    Andreapigna

    Joined:
    Jun 10, 2013
    Posts:
    11
    You just have to create a boolean variable called, idk, Attacking, and then under the Run/Walk/Whatever function you add an if(!Attacking)->animation.Play("walk").
    Reemember to set Attacking to true when you attack, and to set it to false when the animation "attack" ends, so
    yield WaitForSeconds(animation["attack"].length)
    Attacking=false;
    Hope i helped!
     
unityunity