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.
CloseFor 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.
CloseCreate a keyframe.
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); } }
Create a keyframe.
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); } }
Create a keyframe.
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); } }