Animation not playing

Hi all.

My animation wont playing.
Any ideas?

Im try also run anim by script, buts not hapening

    void Awake(){
        AnimationClip animClip2 = Resources.Load<AnimationClip>("anims/player/01/ak47/left");
        if (animClip2 == null){
            throw new UnityException("cant find anim clip");
        }
        anim = GetComponent<Animation>();
        if (anim == null){
            throw new UnityException("cant find anim");
        }
        Debug.Log("a-" + animClip2.name);
        //anim.AddClip(animClip2, "left");

        foreach (AnimationState a in anim){
            Debug.Log("b-" + a.name);
            Debug.Log("c-" + a.time);
            Debug.Log("d-" + a.speed);
            a.enabled = true;
            a.time = 1;
            a.speed = 0.5f;
        }

    }

    void Start () {
        bool ok = anim.Play("right");
        Debug.Log("ok:"+(ok?"1":"0"));
    }

in console i have “ok:1”

When Im add position translation to animation, then after play game object was moving by animation. but sprite was not changed.

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.

That’s a lot of code to play one animation! Try a simpler approach:

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.

1 Like

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

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.