- Home /
Question by
kaiyum · Nov 23, 2013 at 04:45 PM ·
2danimationcliplegacysprite-animation
2D animation can not be found.
Ok. Here is my code:
using UnityEngine;
using System.Collections;
public class animTest : MonoBehaviour {
public AnimationClip anim= new AnimationClip();
private Animation rootAnim;
void Start () {
rootAnim= GetComponent<Animation>();
}
void Update () {
rootAnim.Play(anim.name);
}
}
Here is the error pops up,
The animation state 2dWalk could not be played because it couldn't be found!
Please attach an animation clip with the name '2dWalk' or call this function only for existing animations.
UnityEngine.Animation:Play(String)
animTest:Update() (at Assets/animTest.cs:14)
prob.png
(159.3 kB)
Comment
I don't know if this will help, but maybe it can't find an animation with that name because you have more than one with that name in the Animations list.
also, you don't need to do:
rootAnim= GetComponent<Animation>();
you can just do:
rootAnim = animation;
because it is inherited from monobehavior.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122557im_/https://answers.unity.com/themes/thub/images/avi.jpg)