今天发现这个函数,查了一下,我觉得非常实用.编辑一条任意变化的曲线用在任何你想用在的地方。 如曲线地形,曲线轨迹.
基本用法是:
1.创建物体.
2.创建脚本.
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public AnimationCurve anim;
}
AnimationCurve可以理解为2部分。(1)键序列(2)左右循环模式(又作左右包裹模式)
一:键序列
创建键序列:Keyframe[] ks = new Keyframe[3];
曲线中加入键序列:AnimationCurve curve = new AnimationCurve(ks);
获取曲线中的键序列:curve[index] 或者 curve.keys[index]
添加单键:curve.Addkey(time,value)
删除单键:curve.RemoveKey(index)
二:左右循环
anim.preWrapMode = WrapMode.Loop;
anim.postWrapMode = WrapMode.Once;
三:键
Keyframe kf = new Keyframe(time,value);
kf.inTangent = 45;
kf.outTangent = 45;
例子就丢官方代码上来了:
public AnimationCurve anim;
private Keyframe[] ks;
void Start()
{
ks = new Keyframe[50];
int i = 0;
while (i < ks.Length)
{
ks[i] = new Keyframe(i, i * i);
i++;
}
anim = new AnimationCurve(ks);
}
void Update()
{
transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0);
}
我说下效果吧,就是物体一直斜向上升.