Moving a platform from A to B in Unity

This is about on how to move a platform( or any object) forth and back from point to point. In this example we will use a MoveTowards method.

    public Transform pos1, pos2;
    float speed = 5;
    Vector3 nextPos;

    void Start()
    {
        nextPos = pos1.position;  
    }

    void Update()
    {
        if(transform.position == pos1.position)
        {
            nextPos = pos2.position;
        }

        if (transform.position == pos2.position)
        {
            nextPos = pos1.position;
        }
        transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime);
    }