How to lerp back and forth? (ex. platform)

I give up. I spent hours with no avail. I can move the object from start point to end point using the script from the scripting reference, or any other script I came across, but that’s it.

How can I move the platform back and forth? Or any other object.
I actually need it for a wall that crushes the player but I’ll need it for a platform eventually no doubt.

I don’t understand how it works so I really cant figure it out and I’m surprised that I can’t find anything on making a platform that goes back and forth. Is lerp the way to do it at all? If it is can someone please tell me how, I’m tired and I’m gonna pass out at my desk any min its frustrating. ( -_-)

There are a number of ways of moving things back and forth. One easy way is to use Mathf.PingPong(). There is an example script in the reference. Note if you are using physics, you can add a Rigidbody component, mark it as IsKinematic. Then you will use Rigidbody.MovePosition() for the movement rather than changing Transform.position.

The easiest and most robust way to animate something is to use the animation tools in Unity. It’s possible to do it by script, but if you want to be able to visualize position over time, and tune it in that context, just use the animation tool.

In this case, you want to animate the platform’s position. See the animation editor guide. You may still want to trigger animations by script, though.

If you’re sure you want to animate position by script and Lerp, you should investigate easing functions. These control the rate of an animation or Lerp by a canned progression per time. See some examples and code

Ugh sorry for not replying in like, forever… I’m finally done with college for the moment so I’m back on Unity. Both of your comments really helped me a lot but since I can only accept one answer, I’m accepting the first one. :S

Thank you both really both answers helped!