Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Animation not playing

Discussion in 'Animation' started by tito100, Nov 7, 2016.

  1. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Hi all.

    My animation wont playing.
    Any ideas?

    object settings.png anim settings.png sprite settings.png

    Im try also run anim by script, buts not hapening
    Code (csharp):
    1.  
    2.     void Awake(){
    3.         AnimationClip animClip2 = Resources.Load<AnimationClip>("anims/player/01/ak47/left");
    4.         if (animClip2 == null){
    5.             throw new UnityException("cant find anim clip");
    6.         }
    7.         anim = GetComponent<Animation>();
    8.         if (anim == null){
    9.             throw new UnityException("cant find anim");
    10.         }
    11.         Debug.Log("a-" + animClip2.name);
    12.         //anim.AddClip(animClip2, "left");
    13.  
    14.         foreach (AnimationState a in anim){
    15.             Debug.Log("b-" + a.name);
    16.             Debug.Log("c-" + a.time);
    17.             Debug.Log("d-" + a.speed);
    18.             a.enabled = true;
    19.             a.time = 1;
    20.             a.speed = 0.5f;
    21.         }
    22.  
    23.     }
    24.  
    25.     void Start () {
    26.         bool ok = anim.Play("right");
    27.         Debug.Log("ok:"+(ok?"1":"0"));
    28.     }
    29.  
    in console i have "ok:1"
     
    Last edited: Nov 7, 2016
  2. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    When Im add position translation to animation, then after play game object was moving by animation. but sprite was not changed.
     
  3. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Im try create new project from scratch. But is also not working.
    Im add project to zip see attachment.
    When you run it, then object is moving by animation. but sprite is not changed, see


    Please help me. Im working on this 5 hours and nothings happens.
     
    Last edited: Nov 7, 2016
  4. ryanmillerca

    ryanmillerca

    Joined:
    Aug 12, 2012
    Posts:
    141
    That's a lot of code to play one animation! Try a simpler approach:

    Code (CSharp):
    1. GetComponent<Animation>().Play("left");
    [edit]

    Just saw your comment about sprite changing. You can't change sprites with the legacy animation system; you need to use an Animator instead of an Animation component.
     
    Last edited: Nov 8, 2016
    ShotgunWillie likes this.
  5. tito100

    tito100

    Joined:
    Oct 14, 2016
    Posts:
    22
    Ok. But i need generate animation on The fly. And i cant do it with Animator. What Im try, I cant add AnimationClip to Animator component.
    I have lots of animations, And I not Need it all. So how I can do it?
    And why is not working sprite changing with Animation? everything other is working, changing sprite color is also working
     
  6. ryanmillerca

    ryanmillerca

    Joined:
    Aug 12, 2012
    Posts:
    141
    Legacy animation doesn't support sprite parameter keyframes, nor does it support old legacy animation clips. Nothing you can do about that, as far as I know.

    Sounds like your options are to use the new Animator (mecanim) system 100% and recreate your clips, or to code your own sprite swaps over time. Either way, you won't be using the legacy animation system.