Make an object stationary until player is colliding with it, then move along path.

I’ve been trying to make a script for an elevator. So far I’ve got the movement part done but I can’t figure out how to stop the script from starting before the player is on the elevator object.

This is what I’ve got so far :

public class LiftScript : MonoBehaviour

{
private Vector3 posA;

private Vector3 posB;

[SerializeField]
private float speed;

[SerializeField]
private Transform startPosition;

[SerializeField]
private Transform endPosition;

void Start()
{

    posA = startPosition.localPosition;
    posB = endPosition.localPosition;
}

void Update()
{
    Move();
}

private void Move()
{
    startPosition.localPosition = Vector3.MoveTowards(startPosition.localPosition, posB, speed * Time.deltaTime);
}

}

I’d probably have a collider, smaller than the lift, in the centre, and when the player collides with it, start the movement. This code should help point you in the right direction:

  void OnCollisionEnter()
     {
         Moving=true;
     }

  void OnCollisionExit()
    {
        Moving=false;
    }

   void Update ()
    {
        if (Moving) Move();
    }