Change position of object while it undergoes lerp

So I have a sphere that starts at a position, and needs to move to another position in a specific amount of time.

Vector3 startPosition = new Vector3(0.0f, 0.0f, 0.0f);
Vector3 endPosition = new Vector3(0.0f, 10.0f, 0.0f);
float tSeconds = 2.0f;
float tDelta = 0.0f;


void Update()
{
    tDelta += Time.deltaTime / tSeconds;
    transform.position = Vector3.Lerp(startPosition, endPosition, tDelta);
}

It works fine but what if I need another script to change the sphere’s position on the Y axis to let’s say 2 when it reaches 7. How do I do that without affecting the Update() function inside the sphere itself? I tried to even manipulate it in the editor but the position doesn’t save and resets to where it was before. How do I go about re-creating this function so that I can edit the sphere’s position at any time without rigidbody velocities or other components.

I just figured it out so I guess I’ll answer my own question.

So tDelta as far as I’m concerned is pretty much the current distance calculated from startPosition to endPosition. Resetting this to 0.0f will reset the lerp function back at startPosition. But right before doing that you can change the startPosition and endPosition value to something else. If you want to completely stop the lerp function, chance tDelta to 1.0f.

//******SCRIPT 1*********
public Vector3 startPosition = new Vector3(0.0f, 0.0f, 0.0f);
public Vector3 endPosition = new Vector3(0.0f, 10.0f, 0.0f);
public float tSeconds = 2.0f;
public float tDelta = 0.0f;
     
 void Update()
 {
     tDelta += Time.deltaTime / tSeconds;
     transform.position = Vector3.Lerp(startPosition, endPosition, tDelta);
 }
 //************************

 //******SCRIPT 2*********
    //Find the object and get the script component of it
    object.GetComponent<ScriptName>().startPosition = new Vector3(whatever); //New value
    object.GetComponent<ScriptName>().endPosition = new Vector3(whatever); //New value
    object.GetComponent<ScriptName>().tDelta = 0.0f; //Reset position
//*********************

Something else I can across in my game and it’s a good thing to note is that when you try to set the tDelta value equal to another tDelta value from two similar objects, one will be 1 frame ahead or behind the other. So all you need to do is set the value equal to the other tDelta and add or subtract the frame difference depending if it’s ahead or behind which would be (Time.deltaTime / tSeconds).