I have this code:
GameObject cam;
bool pushed=false;
int i =1;
// float smooth = 5.0f;
Vector3 endpos;
void Update(){
while(pushed ){
cam.transform.position = Vector3.Lerp(cam.transform.position, endpos ,Time.deltaTime/15.0f );
if(cam.transform.position==endpos) pushed=false;
}
}
void OnMouseDown(){
Debug.Log(“mousedown”);
cam= GameObject.Find("Camera");
if(Input.GetMouseButtonDown(0)) {
pushed=true;
endpos=new Vector3(90,90,-8);
}
}
the code above gives me eternal loop. Camera object does not move.
GameObject cam;
bool pushed=false;
int i =1;
// float smooth = 5.0f;
Vector3 endpos;
void Update(){
while(pushed && i <1000 ){
cam.transform.position = Vector3.Lerp(cam.transform.position, endpos ,Time.deltaTime/15.0f );
if(cam.transform.position==endpos) pushed=false;
i++;
}
}
void OnMouseDown(){
Debug.Log("mousedown");
cam= GameObject.Find("Camera");
if(Input.GetMouseButtonDown(0)) {
pushed=true;
endpos=new Vector3(90,90,-8);
}
}
this code moves camera instantly!
I want to move camera smoothly. How to do it?
(BTW I tryed to use Time.deltaTime15.0f and Time.deltaTime1.0f , still no result)