AnimationCurve.keys 所有键

var keys : Keyframe[]

Description描述

All keys defined in the animation curve.

在动画曲线中定义的所有键.

This lets you clear, add or remove any keys from the array. If keys are not sorted by time, they will be automatically sorted on assignment.

这让你从数组中清理,添加,移除任何键.如果键没有按照时间排序,他们会在赋值的时候自动排序.

Note that the array is "by value", i.e. getting keys returns a copy of all keys and setting keys copies them into the curve.

注意:数组是通过值排序.即是:获取键返回一个所有键的副本并设置键的副本到曲线.

See Also: Keyframe struct, AddKey, RemoveKey functions.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	private 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);
	}
}
// Make a GameObject follow a Cuadratic function 
// 使一个游戏对象跟随一个Cuadratic函数
// Over the X and Y axis.
// 在X,Y轴
private var anim : AnimationCurve;
private var ks : Keyframe [];

function Start() {
   ks = new Keyframe [50];
   for(var i = 0; i < ks.Length ; i++){
		ks[i] = Keyframe (i,i*i);    
   }
   anim = new AnimationCurve(ks);
}

function Update() {
   transform.position = Vector3( Time.time ,anim.Evaluate( Time.time ),0);
}
最后修改:2010年12月7日 Tuesday 18:42

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。