gradually zoom in to an object

Hello
I am designing a 3D game that zoom to a 2D picture after a certain amount from entering a certain scene.
In the c# code to zoom into a certain object , every thing works fine yet I want the camera to zoom in gradually not suddenly . to zoom in I changed the field of view of the camera . I tried to use couroutine to make delays while decreasing the field of view gradually , but it made unity stop responding !
-this script is general I can’t make animation for the camera.

so :
how can I zoom gradually without using much of delays, keeping the final view of my 2D picture appropriate wherever the player position was ?

public void ZoomIn ()

{

		cameraZoomIn_new = PictureManager.cameraZoomIn;
		if (cameraZoomIn_new == true) {
		// change the target of the LookAtTarget script to be this gameobject.
		LookAtTarget.target = target;
	GameObject.Find ("FPSController").GetComponent<FirstPersonController> ().enabled = false;
		cam.fieldOfView= 10 ; 
		cameraZoomIn_new = false;
		PictureManager.cameraZoomIn = cameraZoomIn_new;
		
			
		}
	

}

You can use Lerp function and you can achieve the effect you want :slight_smile:
Try looking into Lerp

This script is called by picture manager , along with “move” and “lookattarget” scripts ,it rotate towared the target smoothly , then move towared it slowly then display the picture on the size of the screen . I used empty game objects positioned at appropriate place to view the picture.

first call the script in the manager script

gameObject.GetComponent().ZoomIn();


public void ZoomIn (){

		cameraZoomIn_new = PictureManager.cameraZoomIn;
		if (cameraZoomIn_new == true) {
		// freeze any input from the player
		GameObject.Find ("FPSController").GetComponent<FirstPersonController> ().enabled = false;

		// change the target of the LookAtTarget script to be this gameobject.
		LookAtTarget.target = target;
		Move.targetToMoveTo = viewPoint;
		cam.fieldOfView = 40;

		// reset the zoomin boolean so it only zoom once
		cameraZoomIn_new = false;
		PictureManager.cameraZoomIn = cameraZoomIn_new;

			
		}
	

}

using UnityEngine;
using System.Collections;

public class Move : MonoBehaviour {

public static Move m;
float step ;

static public Transform targetToMoveTo;
public float speed;
void Update() {
	if (targetToMoveTo)      // this if means that this update will occure when the variable in the brackets is called :) 
	
	 step = speed * Time.deltaTime;
	transform.position = Vector3.MoveTowards(transform.position, targetToMoveTo.position, step);
}

}