- Home /
Why doesn't this animation script work?
function Start () {
animation.Play();
}
function Update () {
if (Input.GetAxis ("Horizontal") < 0) {
animation.Play("walkL");
}
else if (Input.GetAxis ("Horizontal") > 0) {
animation.Play("walkR");
}
if (Input.GetAxis ("Vertical") < 0) {
animation.Play("walkB");
}
else if (Input.GetAxis ("Vertical") > 0) {
animation.Play("walkF");
}
}
This is an animation code for my character. I think it's obvious what I'm trying to do, (Animate WASD movement) but I keep getting errors and my character doesn't animate.
The animation state walkF could not be played because it couldn't be found! Please attach an animation clip with the name 'walkF' or call this function only for existing animations. UnityEngine.Animation:Play(String) scriptRockanoidAnimate:Update() (at Assets/scriptRockanoidAnimate.js:16)
Also this error:
(at Assets/scriptRockanoidAnimate.js:2)Default clip could not be found in attached animations list. UnityEngine.Animation:Play() scriptRockanoidAnimate:Start()
Are the animations attached to the object you want to animate?
They are in the blender file. I also put them in the Animation Component in the object.
Answer by MrMonstr · May 04, 2013 at 06:21 PM
For anyone else. I have fixed the problem. Animations need to be set as Legacy. In the rig tab of the object. Change where it says Generic to Legacy. Now it works! :D
Answer by azmat786n · May 03, 2013 at 08:09 PM
//then simply call the function like this
if(Input.GetKeyDown(KeyCode.XX) {
PlayAnimation("animation name as string");
}
//copy below code to your script that object attached animations
//function about play animations
function PlayAnimation(AnimName : String) {
if (!animation.IsPlaying(AnimName))
animation.CrossFadeQueued(AnimName, 0.3, QueueMode.PlayNow);
}
i hope this is helpful to you :D
I used this code, I got the same errors
function PlayAnimation(AnimName : String) {
if (!animation.IsPlaying(AnimName))
animation.CrossFadeQueued(AnimName,0.3, Queue$$anonymous$$ode.PlayNow);
}
function Update () {
if (Input.GetAxis ("Horizontal") < 0) {
PlayAnimation("walkL");
}
else if (Input.GetAxis ("Horizontal") > 0) {
PlayAnimation("walkR");
}
if (Input.GetAxis ("Vertical") < 0) {
PlayAnimation("walkB");
}
else if (Input.GetAxis ("Vertical") > 0) {
PlayAnimation("walkF");
}
}
Do tell me if this is wrong.
If you are still getting the same errors as above, the animations are not attached to the object correctly. I dont know how else to help you other than to tell you to double check that the animations are attach to the same object that this script is attached to, and all the names match exactly
wait i am checking your script and also finding your another problems :)
please put here which error you faced now using this script...?
delete all of above your script create new scene and put your animated object in their scene then delete previous component from object add animation component new then add one animation and in the animation component options check (Play automatically) second step also select (Always Animate) then test if your object animate in play mode then fine if not play then your object not properly exported from blender :) lets do it this is the final way to check your problem ...