- Home /
AddClip from same fbx file with different frame start and end
This worked for me
//reference to your animation component
Animation anim;
//file name of the fbx file
string filename = "your file name without the file extension";
//initial instance of the clip from the fbx file
AnimationClip clip = (UnityEngine.Object.Instantiate(Resources.Load("Animations/" + filename) as GameObject, Vector3.zero, Quaternion.identity) as GameObject).GetComponent<Animation>().clip;
//create 1st copy
AnimationClip clip01 = UnityEngine.Object.Instantiate(clip as AnimationClip, Vector3.zero, Quaternion.identity) as AnimationClip;
clip01.name = filename + "_firstcycle";
//create 2nd copy
AnimationClip clip02 = UnityEngine.Object.Instantiate(clip as AnimationClip, Vector3.zero, Quaternion.identity) as AnimationClip;
clip02.name = filename + "_loopcycle";
//create 3rd copy
AnimationClip clip03 = UnityEngine.Object.Instantiate(clip as AnimationClip, Vector3.zero, Quaternion.identity) as AnimationClip;
clip03.name = filename + "_endcycle";
//read all frames
int frames = Mathf.CeilToInt (clip.length * clip.frameRate);
//add clips to Animation component
anim.AddClip(clip01, clip01.name, 0, 10, false);
anim.AddClip(clip02, clip02.name, 10, 20, false);
anim.AddClip(clip03, clip03.name, 20, frames, false);
//play clip sequence starting with first, then 3x2nd and 3rd
anim.PlayQueued (clip01.name);
anim.PlayQueued (clip02.name);
anim.PlayQueued (clip02.name);
anim.PlayQueued (clip02.name);
anim.PlayQueued (clip03.name);
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
changing animations on an object without the script. 0 Answers
How do I play legacy animations properly in Unity C# 1 Answer