Cal W
Cal W

Reputation: 167

Add animation clips to the Animation component

In unity in the Animation component there is the array of Animations. I need to be able to set the elements of that array from a script. How would I go about doing this. I found nothing of help in the scripting API for the Animation. Is this even possible?

Upvotes: 0

Views: 2189

Answers (1)

Programmer
Programmer

Reputation: 125315

To set the default animation clip, the Animation.clip property is used.

enter image description here

To add animation clips, the Animation.AddClip function is used.

enter image description here

Example for both:

public AnimationClip clip;
public Animation anim;

void Start()
{
    anim.clip = clip;

    anim.AddClip(clip, "Jump");
    anim.AddClip(clip, "Run");
}

I need to be able to set the elements of that array from a script. How would I go about doing this.

I think that are looking for AddClip above. Note that you'll need to mark the animation clip as Legacy. If you don't do this, the AddClip will give you warning messages and will not add the animation to the array.

Upvotes: 1

Related Questions