I added an Animation component to a gameobject, then set the size of animations to 3, then assigned the animation clips to the 3 slots.
–. First I try to access the animations this way,
public Animation[] anim;
anim = gameObject.GetComponents<Animation>();
anim[0].Play();
anim[1].Play();
But I will get error when it reaches anim[1]
IndexOutOfRangeException: Index was outside the bounds of the array.
I guess I can’t access their array?
–. Then I tried to build my own array
public Animation[] anim;
Then set the anim size to 3 in inspector, I’m UNABLE to assign animation clips to the slots in script component…
–. Lastly I tried access animation clip by it’s name: “Armature|idle01”,etc.
gameObject.GetComponent<Animation>().Play("Armature|idle01");
I get error:
The animation state Armature|idle01 could not be played because it couldn’t be found!
Please attach an animation clip with the name ‘Armature|idle01’ or call this function only for existing animations.
I’m seriously confused.
Thanks this helped me. If you have a bunch of animation clips and you do not want to type the names manually then. Create an array with the animation clips and order them same as in the Animation component. Now you can ask for the animation clip name from that array when you want to pass the animation name string to the animcomp.Play("Clipname");
– RIPANN