Got a simple script here that, when attached to a cube, will animate it’s position in a nice sinusodal fashion.
public class Sine : MonoBehaviour
{
public AnimationCurve anim;
private Keyframe[] kf; // show in inspector
void Start()
{
kf[0] = new Keyframe(0, 0f, 0, 0);
kf[1] = new Keyframe(0.5f, 3f, 0, 0);
kf[2] = new Keyframe(1, 0f, 0, 0);
anim = new AnimationCurve(kf);
}
void Update()
{
transform.position = new Vector3(3, anim.Evaluate(Time.time), 0);
}
}
However, I have no idea to get the animation to loop once the last keyframe has played. Any ideas?