Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

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

Keyframe.Keyframe

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

Sumbission failed

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

Close

Cancel

public function Keyframe(time: float, value: float)
public Keyframe(float time, float value);
public def Keyframe(time as float, value as float)

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); }
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, Mathf.Sin(i));
            i++;
        }
        anim = new AnimationCurve(ks);
    }
    void Update() {
        transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private anim as AnimationCurve

	private ks as (Keyframe)

	def Start() as void:
		ks = array[of Keyframe](50)
		i as int = 0
		while i < ks.Length:
			ks[i] = Keyframe(i, Mathf.Sin(i))
			i++
		anim = AnimationCurve(ks)

	def Update() as void:
		transform.position = Vector3(Time.time, anim.Evaluate(Time.time), 0)

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

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); }
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, Mathf.Sin(i), 90, 90);
            i++;
        }
        anim = new AnimationCurve(ks);
    }
    void Update() {
        transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0);
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	private anim as AnimationCurve

	private ks as (Keyframe)

	def Start() as void:
		ks = array[of Keyframe](50)
		i as int = 0
		while i < ks.Length:
			ks[i] = Keyframe(i, Mathf.Sin(i), 90, 90)
			i++
		anim = AnimationCurve(ks)

	def Update() as void:
		transform.position = Vector3(Time.time, anim.Evaluate(Time.time), 0)