x


Access Animations array in Animation component

In the animation component, there is the default Animation, and also an Animations array. How do you access a particular animation in this array, for play at an arbitrary time during run time?

The obvious animation.animations[index] does not work.

more ▼

asked Jun 30 '11 at 03:21 AM

ina gravatar image

ina
3.3k 492 551 602

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

the array you're accessing in your example is the animation state- so it's still useful for your purposes, just not in the way you were using it.

try something like:

animation.CrossFade(animation.animations[index].name);

more ▼

answered Jun 30 '11 at 03:32 AM

testure gravatar image

testure
4.2k 20 25 48

same error: BCE0019: 'animations' is not a member of 'UnityEngine.Animation'. Did you mean 'animateOnlyIfVisible'?

Jun 30 '11 at 03:47 AM ina

er.. sorry. that's what I get for hastily doing a copy/pasta.

you actually cant access animations by index. not out-of-the-box anyway. the easiest way to do something like this is to build your own array/list and add them that way.

example:

List<string> animations = new List<string>();

void Start()
{

   foreach(AnimationState state in animation)
   {
      animations.Add(state.name);
   }
}

void Update()
{
    // now you can do whatever you need to do by index.
}
Jun 30 '11 at 03:55 AM testure
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3807
x1363
x302
x54

asked: Jun 30 '11 at 03:21 AM

Seen: 2536 times

Last Updated: Jun 30 '11 at 03:59 AM