How do simple moving platform?

How do simple moving platform?

just look at the code and differences, this code works I know, I already checked it.

If you need help understanding why it works compared to your code let me know.

using UnityEngine;
using System.Collections;

public class Random : MonoBehaviour {
	public static float movespeed; //how quickly the platform moves
	public Vector3 Direction;      //direction of travel
	public float TravelDistance;    //how far to move before reverse
		Vector3 StartPos;
	public void Start(){
		movespeed = 2f;
		TravelDistance = 2f;
		Direction = Vector3.right;
		StartPos = transform.position;
	public void Update(){
		if (transform.position.x > StartPos.x + TravelDistance)
			Direction = -Direction;
		if (transform.position.x < StartPos.x)
			Direction = Vector3.right;
		transform.Translate(Direction * movespeed * Time.deltaTime);

it does quite a few different. it uses vector3 not 2.

it doesn’t have hardcoded values for when to turn around but just takes wherever the object starts and turns around a set distance from the start point.
those are the main things. it also seperates declaring a variable and assigning it.