function SetCurve (relativePath : String, type : Type, propertyName : String, curve : AnimationCurve) : void
Parameters
Name | Description |
relativePath |
The path to the game object this curve applies to. relativePath is formatted similar to a pathname, e.g. "root/spine/leftArm". If relativePath is empty it refers to the game object the animation clip is attached to.
|
type |
The class type of the component that is animated
|
propertyName |
The name or path to the property being animated
|
curve |
The animation curve
|
Description
Assigns 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.
function Start () {
var curve : AnimationCurve = AnimationCurve.Linear(0, 1, 2, 3);
var clip : AnimationClip = new AnimationClip();
clip.SetCurve("", Transform, "localPosition.x", curve);
animation.AddClip(clip, "test");
animation.Play("test");
}
@script RequireComponent(Animation)
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animation))]
public class example : MonoBehaviour {
void Start() {
AnimationCurve curve = AnimationCurve.Linear(0, 1, 2, 3);
AnimationClip clip = new AnimationClip();
clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
animation.AddClip(clip, "test");
animation.Play("test");
}
}
import UnityEngine
import System.Collections
[RequireComponent(Animation)]
class example(MonoBehaviour):
def Start():
curve as AnimationCurve = AnimationCurve.Linear(0, 1, 2, 3)
clip as AnimationClip = AnimationClip()
clip.SetCurve('', Transform, 'localPosition.x', curve)
animation.AddClip(clip, 'test')
animation.Play('test')
Material properties can be animated using the property name exported in the shader.
Common property names are: "_MainTex", "_BumpMap", "_Color", "_SpecColor", "_Emission".
How to animate different material property types:
- Float properties: "PropertyName"
- Vector4 properties: "PropertyName.x", "PropertyName.y", "PropertyName.z", "PropertyName.w"
- Color properties "PropertyName.r", "PropertyName.g", "PropertyName.b", "PropertyName.a"
- UV Rotation properties "PropertyName.rotation"
- UV Offset and scale "PropertyName.offset.x", "PropertyName.offset.y", "PropertyName.scale.x", "PropertyName.scale.y"
- To index into multiple materials on the same renderer you can prefix the attribute like this: "[1]._MainTex.offset.y"
See Also: ClearCurves function,
AnimationCurve class.
function Start () {
var clip = new AnimationClip ();
clip.SetCurve ("", Material, "_Color.a",
AnimationCurve (Keyframe(0, 0, 0, 0), Keyframe(1, 1, 0, 0)));
clip.SetCurve ("", Material, "_MainTex.offset.x",
AnimationCurve.Linear(0, 1, 2, 3));
animation.AddClip (clip, clip.name);
animation.Play(clip.name);
}
@script RequireComponent(Animation)
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animation))]
public class example : MonoBehaviour {
void Start() {
AnimationClip clip = new AnimationClip();
clip.SetCurve("", typeof(Material), "_Color.a", new AnimationCurve(new Keyframe(0, 0, 0, 0), new 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);
}
}
import UnityEngine
import System.Collections
[RequireComponent(Animation)]
class example(MonoBehaviour):
def Start():
clip as AnimationClip = AnimationClip()
clip.SetCurve(, Material, '_Color.a', AnimationCurve(Keyframe(0, 0, 0, 0), Keyframe(1, 1, 0, 0)))
clip.SetCurve(, Material, '_MainTex.offset.x', AnimationCurve.Linear(0, 1, 2, 3))
animation.AddClip(clip, clip.name)
animation.Play(clip.name)