I currently have an imported FBX with an animation that controls its children. I have a selection script so that if I click on any part of the model and drag the mouse, the animation will play. In this instance, it’s a model of a throttle with two levers as children. I want to make it so that if I click on a lever, it will only move that specific lever instead of both. So far, I have a script that attaches a new animation to each child that originally had curves on it, and also attaches an animation clip with curves. The problem is, these curves aren’t correct and I’m not sure where they’re coming from. Here’s what I have:
var curvePaths : List.<String> = new List.<String>();
var curveTypes : List.<System.Type> = new List.<System.Type>();
var curvePropertyNames : List.<String> = new List.<String>();
var curves : AnimationClipCurveData[];
var testClip : AnimationClip;
var sceneObjects : GameObject[] = FindObjectsOfType(GameObject) as GameObject[];
for (var sceneObject in sceneObjects) {
if (sceneObject.animation != null) {
if (sceneObject.animation.clip != null) {
var i = 0;
testClip = sceneObject.animation.GetClip("Take 001");
curves = AnimationUtility.GetAllCurves(sceneObject.animation.clip);
for (var curve in curves) {
curvePaths.Add(curve.path);
curveTypes.Add(curve.type);
curvePropertyNames.Add(curve.propertyName);
for (var curvePath in curvePaths) {
var newAnimation : Animation;
var newClip : AnimationClip = new AnimationClip();
var realObject = GameObject.Find(curvePath);
if (realObject.animation == null) {
newAnimation = realObject.AddComponent(Animation);
}
newClip.SetCurve("", curveTypes_, curvePropertyNames*, curve.curve);*_
* realObject.animation.AddClip(newClip, “Take 001”);*
}
i++;
}
DestroyImmediate(sceneObject.animation);
}
}
}