Legacy Documentation: Version 2018.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

Keyframe Constructor

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 Keyframe(time: float, value: float)
public Keyframe(float time, float value);

Description

Create a keyframe.

// Make a GameObject follow a Sinus 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,Mathf.Sin(i));

anim = AnimationCurve(ks); }

function Update() { transform.position = Vector3(Time.time,anim.Evaluate(Time.time),0); }
no example available in C#

public Keyframe(time: float, value: float, inTangent: float, outTangent: float)
public Keyframe(float time, float value, float inTangent, float outTangent);

Description

Create a keyframe.

// Make a GameObject follow a Sinus function
// Over the X and Y axis with vertical tangents.

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,Mathf.Sin(i),90,90); } anim = AnimationCurve(ks); }

function Update() { transform.position = Vector3(Time.time,anim.Evaluate(Time.time),0); }
no example available in C#

public Keyframe(time: float, value: float, inTangent: float, outTangent: float, inWeight: float, outWeight: float)
public Keyframe(float time, float value, float inTangent, float outTangent, float inWeight, float outWeight);

Description

Create a keyframe.

// Make a GameObject follow a Sinus function
// Over the X and Y axis with linear interpolation.

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,Mathf.Sin(i),0,0,0,0); } anim = AnimationCurve(ks); }

function Update() { transform.position = Vector3(Time.time,anim.Evaluate(Time.time),0); }
no example available in C#

Did you find this page useful? Please give it a rating: