Lerp not working with UI button
Hi All,
I want to call this lerp function with a UI button. However, when I change it from an update to a public void, the object just moves instantaneously without the smooth lerp I'm after. Is there a way to leave it in update and use it as a function for a UI button?
Many Thanks
{
public Transform startMarker;
public Transform endMarker;
public float speed = 1.0f;
private float startTime;
private float journeyLength;
void Start ()
{
startTime = Time.time;
journeyLength = Vector3.Distance (startMarker.position, endMarker.position);
}
//void Update()
public void moveLeft()
{
float distcovered = (Time.time - startTime) * speed;
float fracJourney = distcovered / journeyLength;
transform.position = Vector3.Lerp (startMarker.position, endMarker.position, fracJourney);
}
}
Comment
Answer by OncaLupe · Dec 06, 2015 at 10:49 PM
You set startTime in Start(), but don't use it until moveLeft() by which Time has advanced. You should move both lines from Start() to moveLeft().