AnimationClip.SetCurvefunction SetCurve (relativePath : string, type : Type, propertyName : string, curve : AnimationCurve) : voidParameters
DescriptionAssigns the curve to animate a specific property. If curve is null the curve will be removed. If a curve already exists for that property, it will be replaced. Common names are: "localPosition.x", "localPosition.y", "localPosition.z", "localRotation.x", "localRotation.y", "localRotation.z", "localRotation.w" "localScale.x", "localScale.y", "localScale.z". For performance reasons Transform position, rotation and scale can only be animated as one property. /// Animates the x coordinate of a transform position function Start () { // Create the curve var curve = AnimationCurve.Linear(0, 1, 2, 3); // Create the clip with the curve var clip = new AnimationClip(); clip.SetCurve("", Transform, "localPosition.x", curve); // Add and play the clip animation.AddClip(clip, "test"); animation.Play("test"); } @script RequireComponent(Animation) Material properties can be animated using the property name exported in the shader. Common property names are: "_MainTex", "_BumpMap", "_LightMap", "_Color", "_SpecColor", "_Emission". How to animate different material property types:
// Animate color's alpha and main texture's horizontal offset. function Start () { var clip = new AnimationClip (); clip.SetCurve ("", typeof(Material), "_Color.a", AnimationCurve (Keyframe(0, 0, 0, 0), Keyframe(1, 1, 0, 0))); clip.SetCurve ("", typeof(Material), "_MainTex.offset.x", AnimationCurve.Linear(0, 1, 2, 3)); animation.AddClip (clip, clip.name); animation.Play(clip.name); } @script RequireComponent(Animation) See Also: ClearCurves function, AnimationCurve class.
|
