Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

AnimationCurve.keys

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public var keys: Keyframe[];
public Keyframe[] keys;

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.

// Make a GameObject follow a Quadratic function
// Over the X and Y axis.

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); }
using UnityEngine;
using System.Collections;

public class ExampleClass : 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); } }