Search Unity

Problem with C# Animation Controller Feature

Discussion in 'Animation' started by HelloKity1231, Sep 22, 2013.

  1. HelloKity1231

    HelloKity1231

    Joined:
    Nov 25, 2012
    Posts:
    121
    Hello, i use the new feauture of Unity, "Animation Controller"

    I have "dokebimusa (free from unity asset store)", this model has already 2 animations, idle run.
    I added to this model AnimationController and i add another animation "attack animation".

    How i can play the new animation from C# script?

    I appended animation list on model, i added "attack" clip also but i can't see(manage) it from script. (it is like it does not exist)

    Without code it works, but it always run "attack" clip, i wan't to change between character state, idle, run, attack.

    Any help? soz for my bad english!
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,697
    Watch this tutorial: http://video.unity3d.com/video/7362044/unity-40-mecanim-animation-tutorial. It contains all the steps you need.

    Very briefly:

    1. Make sure the models and animations are imported as Humanoid. Your character should have an Animator component, and not an Animation component. If the attack clip is only an .anim file, make sure it's Mecanim-compatible. I suspect your problem might be in this step.

    2. In the Animator window:

    a. Right-click on Idle and select Set as Default.
    b. Add a Boolean Parameter named Attacking.
    c. Right-click on Any State and select Make Transition, then click on Attack.
    d. Click on the transition arrow. Change the transition condition to "Attacking==true".

    3. In your code, when you want the character to attack, use something like this code:

    Code (csharp):
    1. GetComponent<Animator>().SetBool("Attacking", true);
    This is not complete or robust, but will hopefully get you started.