In my little test project, i decided that I want to lern how to use animationcurve.
There is not much documentation but i managed to have an object move using a curve i created.
Unfortunately, the object continue to move into infinity since i dont know how to tell it to stop.
The problem is, i have no idea how to specify a lengh of time for my curve and tell my script to stop running when it reached it.
Strangely, curve.length tells me the number of key, which is not what i want.
Let’s say i want to animate a light.range, with a min intensity and a max intensity, over a specified time, using a curve how would i do that in C#?
I searched a lot and i couldn’t find an answer that can be apply to my situation.
My solution in C# which I believe is the same as the steps outlined:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CurveQues : MonoBehaviour
{
public AnimationCurve curve;
private float curveTime;
private float lastKeyTime;
void Start()
{
FindLastKey();
}
void FindLastKey()
{
//Get the last keyframe and log it's time
Keyframe lastKey = curve[curve.length - 1];
lastKeyTime = lastKey.time;
}
void Update()
{
curveTime += Time.deltaTime;
if (curveTime < lastKeyTime)
{
// Do stuff like curve evaluation
}
else
{
// End of animation curve!
}
}
}