- Home /
Animation.Play(useVar)
Before i talk about this, take a look below and also error log.
Code:
//FOR ANIMATION static var leveldiff : String = "lv1easy"; private var num001; private var num002; private var num003; private var num004; private var num005; var enemystartonce : boolean = true;
//ANIMATION LIST: // Level 1 EASY var lv1easy; var lv1easy001 : AnimationClip; var lv1easy002 : AnimationClip; var lv1easy003 : AnimationClip; var lv1easy004 : AnimationClip; var lv1easy005 : AnimationClip;
function randomanim() { var randomanimation : int = Random.Range(1,5); print(randomanimation);
if (leveldiff == lv1easy) //Level 1 Easy
{
num001 = lv1easy001;
num002 = lv1easy002;
num003 = lv1easy003;
num004 = lv1easy004;
num005 = lv1easy005;
return;
}
//START ONCE!
if (enemystartonce == true) {
enemystartonce = false;
animation.Play(num001);
return;
}
yield WaitForSeconds(animation.clip.length);
//START RANDOM ANIMATION
if (randomanimation == 1)
{
animation.Play(num001);
return;
}
else if (randomanimation == 2)
{
animation.Play(num002);
return;
}
else if (randomanimation == 3)
{
animation.Play(num003);
return;
}
else if (randomanimation == 4)
{
animation.Play(num004);
return;
}
else if (randomanimation == 5)
{
animation.Play(num005);
return;
}
}
Unity Error said that "The animation state could not be played because it couldn't be found! Please attach an animation clip with the name '' or call this function only for existing animations."
I want to make it random play animation per each level and difficulty level and make "animation.play()"
Thanks.
do you have a default animation attached to your object?
Your answer
![](https://koobas.hobune.stream/wayback/20220613083553im_/https://answers.unity.com/themes/thub/images/avi.jpg)