Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Keyframe

Create a keyframe.
Read time 1 minuteLast updated 7 days ago

Definition

  • Type: Constructor
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

Keyframe(float, float)

Create a keyframe.
public Keyframe(float time, float value)

Parameters

time


value

Examples

using UnityEngine;public class Example : MonoBehaviour{ // Make a GameObject follow a sine function. // Over the X and Y axis. AnimationCurve anim; Keyframe[] ks; void Start() { ks = new Keyframe[50]; for (var i = 0; i < ks.Length; i++) { ks[i] = new Keyframe(i, Mathf.Sin(i)); } anim = new AnimationCurve(ks); } void Update() { transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0); }}

Keyframe(float, float, float, float)

Create a keyframe.
public Keyframe(float time, float value, float inTangent, float outTangent)

Parameters

time


value


inTangent


outTangent

Examples

using UnityEngine;public class Example : MonoBehaviour{ // Make a GameObject follow a sine function. // Over the X and Y axis. AnimationCurve anim; Keyframe[] ks; void Start() { ks = new Keyframe[50]; for (var i = 0; i < ks.Length; i++) { ks[i] = new Keyframe(i, Mathf.Sin(i), 90, 90); } anim = new AnimationCurve(ks); } void Update() { transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0); }}

Keyframe(float, float, float, float, float, float)

Create a keyframe.
public Keyframe(float time, float value, float inTangent, float outTangent, float inWeight, float outWeight)

Parameters

time


value


inTangent


outTangent


inWeight


outWeight

Examples

using UnityEngine;public class Example : MonoBehaviour{ // Make a GameObject follow a sine function. // Over the X and Y axis. AnimationCurve anim; Keyframe[] ks; void Start() { ks = new Keyframe[50]; for (var i = 0; i < ks.Length; i++) { ks[i] = new Keyframe(i, Mathf.Sin(i), 0, 0, 0, 0); } anim = new AnimationCurve(ks); } void Update() { transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0); }}