i want my camera to smoothly move to the new position. unfortunatly this is not working.
the script waits until the time is over and then it suddenly changes position, but doesnt interpolate between my 2 values. what am i doing wrong? also when i put a yield command in there my gui dissapears…
heres my script, hope someone can help me…
if (GUI.Button (Rect (6,60,100,20), "Set as Center")){
var i = 0.0;
var rate = 1.0/9;
meineCam.GetComponent(Mouse).target = GameObject.Find(this.name +"target").transform;
var oldPosition = Vector3(meineCam.transform.position.x, meineCam.transform.position.y, meineCam.transform.position.z);
var newPosition = Vector3(GameObject.Find(this.name +"target").transform.position.x , GameObject.Find(this.name +"target").transform.position.y, meineCam.transform.position.z);
while (i < 1.0) {
i += Time.deltaTime * rate;
meineCam.transform.position = Vector3.Lerp(oldPosition, newPosition, i);
}
}
thanks a lot!