Moving an object

I’m trying to write a small code to smootly move a cube from it’s starting position to it’s target position. I found a code on this website but I’m not sure how to use it.

var start : Transform;
var end : Transform;

function Update ()
    transform.position = Vector3.Lerp(start.position, end.position, Time.time); 

This makes the object go to 0,0,0 in a matter of seconds, how do I specify the end position?

Also I would like if the object would be transparent before and after moving.

Try this.

  1. Go on your scene

  2. Create an empty game object and place it at the end position

  3. GO on your script where you are doing the LERP and type this code.

    public Transform target;

    transform.position = Vector3.Lerp(start.position, target.position, Time.time);

  4. In the Unity editor, drag the ‘target’ game object onto the public field target.