Let’s break the line of code down to help determine why the object can move:
transform.Translate(Vector3.right * Time.deltaTime);
- Transform is the object that we want to move. Therefore, the transform in this example is the cube
- Translate is one of the many public methods that can be used when calling on the transform. In this case, translate moves the object in the direction and distance of the translation.
- Vector3 is the representation of the transform’s position in a 3D world environment. It’s made up of 3 numbers, representing the X,Y,Z coordinates. Using Vector3.right is a shortcut of saying
- Time.deltaTime represents the interval from the last frame to the current one in seconds. As the Update method in Unity is called once per frame (usually 60fps), without adding it means the object will be moving 60 m/s. By multiplying this with the Vector3, it slows down the object to 1 m/s.
Using all these information, along with additional research, means you can turn a cube that moves right all the time to