"Sliding Door" - Lerp object side to side

Hi all,
I’ve been trying for a while now to get this to work. I’m not entirely sure where I went wrong, but here is the script I’ve made:

    public Vector3 offset;
    public float smoothing;
    int number;

    void Start()
    {
        number = 0;
    }

	void Update ()
    {
	    if(Input.GetKeyDown(KeyCode.E))
        {
            DoorSlide();
        }
	}

    void DoorSlide()
    {
        if (number == 0)
        {
            transform.position = Vector3.Lerp(transform.position, transform.position + offset, Time.deltaTime * smoothing);
            number++;
        }
        else
        {
            transform.position = Vector3.Lerp(transform.position, transform.position - offset, Time.deltaTime * smoothing);
            number--;
        }
    }

I’m setting it up so I can open and close the door by pressing E. I’d like the door to “slide” from it’s current position (either open or closed) to its other position.

The difficulty I’m having is that the door opens and closes with the above script, but it snaps from its initial position to its final position. There is no lerping happening.

Any and all suggestions are welcome, and thank you in advance for your time!

I’m going to answer this 6 years later for anybody whose curious - the reason is because lerps need to be done in a while lerp to continually move. Drop it in an IENumerator and have a float for howlong you want it to go for.

            while (elapsedTime < howlong)
            {
                transform.position = Vector3.Lerp(start, des, elapsedTime);
                elapsedTime += Time.deltaTime;
                yield return null;
            }

The key press after you add one to ‘number’ you subtract one since it is no longer 0.

Try adding a flag for if the door is sliding open or closed, and adding or subtracting accordingly.

Also you modify number, but use offset to move the object. That won’t work.