How stop Update when Lerp is finished?

In my update function I execute a LERP to position my button.
The problem is, once the button has reached its final position, the Lerp function keeps getting executed every update (30 to 60 times per second).
I don’t need the update function anymore when the LERP is finished. How do I achieve this?

void Update() {
	transform.localPosition = new Vector3(startpos.x, Mathf.Lerp(startpos.y, maximum, Time.time), startpos.y);
}

bool lerping = true;
Vector3 endPos;

void Update()
{
     if(lerping)
    {
         MoveButton();
         if(transform.position == endPos)
         {
               lerping = false;
         }
    }
}

void MoveButton()
{
    //Put your lerp here.
}

This is how I’ve been doing it anyway :slight_smile:

You can’t exactly remove the Update function. In your case, all you would need to do is just return once the t value of the Lerp is greater than 0, i.e.

     void Update() {
         if (Time.time > 1)
             return;

         transform.localPosition = new Vector3(startpos.x, Mathf.Lerp(startpos.y, maximum, Time.time), startpos.y);
     }