Maybe not the prettiest solution but here’s what I threw together to make the block move back and forth
[SerializeField] Vector3 movementVector;
[Range(0, 1)] [SerializeField] float movementFactor;
Vector3 startingPos;
bool reachedMax = false;
float speedFactor = 0.25f;
// Use this for initialization
void Start ()
{
startingPos = transform.position;
}
void Update ()
{
AdjustMovementFactor();
Vector3 offset = movementVector * movementFactor;
transform.position = startingPos + offset;
}
void AdjustMovementFactor()
{
if (movementFactor == 1.0f)
reachedMax = true;
if (!reachedMax)
movementFactor += Mathf.Min(Time.deltaTime * speedFactor, 1.0f - movementFactor);
else
{
movementFactor -= Mathf.Min(Time.deltaTime * speedFactor, movementFactor);
if (movementFactor == 0.0f)
reachedMax = false;
}
}