How can i move object between two positions ?

I want to move the object between the distance 0 and 100.
move it to the right when the distanceTravelled is get to 100 change direction.
When it’s getting to 0 again change direction again and so on.

And second option i want to make that when the distanceTravelled is got to 100 change direction and then when the object is getting to it’s originalPosition change direction again.

How can i make this both cases ? ( Each case alone but how to make them ? i mean same script but each time with the other option)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveObject : MonoBehaviour {

    public float moveSpeed = 2.0f;
    private float distanceTravelled;
    private Vector3 originalPosition;

	// Use this for initialization
	void Start ()
    {
        originalPosition = transform.position;
	}

    // Update is called once per frame
    void Update()
    {
        distanceTravelled += Vector3.Distance(originalPosition, transform.position);
        
        if (distanceTravelled < 100f)
            transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);


        if (distanceTravelled >= 100f)
        {
            transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
        }
    }
}

public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);

You set up 2 Vectors, this way you make the two endpoints you would like to move your object, When movetowards reaches its target it’ll return its Destination.

Vector3 Destination = new Vector3(0,0,100);
Vector3 Traveller = new Vector3(0,0,0);
float step = 2.5f;
while(Traveller != Destination){
Traveller = Vector3.MoveTowards(Traveller, Destination, Step);
}

I reccomend you to implement this in a Coroutine.

This script (for 2D) will continuously move and object back and forth between two points:

using System;
using UnityEngine;

public class MoveObject : MonoBehaviour
{
    public Vector2 OriginPoint;
    public Vector2 DestinationPoint;
    public float Speed = 20.0f;

    protected float timeElapsed = 0;

    void FixedUpdate()
    {
        transform.position = Vector3.MoveTowards(OriginPoint, DestinationPoint, timeElapsed);
        timeElapsed += Speed * Time.deltaTime;

        if ( Math.Abs(transform.position.x - DestinationPoint.x) < 1 &&
             Math.Abs(transform.position.y - DestinationPoint.y) < 1)
        {
            Vector2 temp = OriginPoint;
            OriginPoint = DestinationPoint;
            DestinationPoint = temp;
            timeElapsed = 0;
        }
    }
}