i trying to make a script so that a cube or more go from one to another and back how do i do it??
var targetA : GameObject;
var targetB : GameObject;
var speed : float = 0.1;
function FixedUpdate () {
var weight = Mathf.Cos(Time.time * speed * 2 * Mathf.PI) * 0.5 + 0.5;
transform.position = targetA.transform.position * weight
+ targetB.transform.position * (1-weight);
}
This code animates an object between two points identified by the targetA and targetB game objects which you can set in the inspector. (Stolen from the 2D platformer tutorial.)