Hi,
I read the documentation about animation curves, here : Unity - Scripting API: AnimationCurve.AnimationCurve
When I tried to run the supplied script, I got the following error :
It is easy to fix, by creating a new Vector3. If you use this code though and apply it on a cube, you will see the cube going up and to the right, disappearing from the screen.
Perhaps using the WrapMode as follows could provide a more interesting example. You get a cube that goes up and down. User can modify the curve characteristics in Editor during runtime and watch how the cube motion changes.
using UnityEngine;
using System.Collections;
public class AnimCurveExample : MonoBehaviour
{
public AnimationCurve curve ;
void Start()
{
curve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
curve.preWrapMode = WrapMode.PingPong;
curve.postWrapMode = WrapMode.PingPong;
}
void Update()
{
transform.position = new Vector3(transform.position.x, curve.Evaluate(Time.time), transform.position.z);
}
}