How do you make a GameObject move on Update endlessly?
I know a little about C#, but I'm a student learning. We have Virtual-Hammer to make things easier, it's essentially like Blueprints in Unreal Engine. My game has a crate that a character must jump on, but I want the crate to go up and down on it's own in a repetitive cycle. When the game starts it's at 19.65 on the Y-axis. I want it to move from 8 all the way to 40 on the y-axis. It doesn't need to move on any other axis. I'm creating a 2D side scrolling game. If you can help that would be amazing! Thank you!
Answer by Hellium · Mar 07, 2018 at 04:06 PM
Very simple script you can attach to your crate:
// Crate.cs
using UnityEngine;
public class Crate : SV3Dswipe.SVMonoBehaviour
{
public AnimationCurve PositionCurve;
protected void Update()
{
transform.position = Vector3.up * PositionCurve.Evaluate( Time.time );
}
}
Then, in the inspector, you will see a grey box. Click on it, and select one of the preset at the bottom of the window.
Right click on the left point, click "Edit" and change the value to 8
Right click on the rightpoint, click "Edit" and change the value to 40, and change the time to the value you want.
Finally, click on the gear, next to the right point and select "Ping Pong", or "Loop".
Click Play and you will see your crate moving on the Y axis according to the curve you've set.
Your answer
![](https://koobas.hobune.stream/wayback/20220612154115im_/https://answers.unity.com/themes/thub/images/avi.jpg)