zooming camera out then back in

hey all, im creating a feature so at the start of the level the camera zooms out to show the map then zooms back in. so far my camera zooms out however when its coded to zoom back in, it does nothing, it just stops zooming altogether. its orthographic btw so im changing size.
im using camera.orthographicSize += Time.deltaTime * speedZoom;
to zoom out and zooming in by swicthing the - to a +.

heres my full script

using UnityEngine;

using System.Collections;

 

public class IsometricCamera : MonoBehaviour

{

    private GameObject target;
	
	public GameObject TargettoBall;
	
	public float speedZoom = 9;

    public float size = 10;
	private float EndZoom = 15;

    public float scrollSpeed = 30;
	private float maxPos = 9;
	private bool StartLevelMove = true;
	private bool Zoomedout = false;
	
	// zoom in-out buttons
	public GUITexture ZoomIN;
	public GUITexture ZoomOUT;
	//public Texture2D ZoomIN;
	//public Texture2D ZoomOUT;


    private Camera cam;

 
	
    void Start()

    {

        this.cam = (Camera)this.gameObject.GetComponent("Camera");

        this.cam.isOrthoGraphic = true;

        this.cam.transform.rotation = Quaternion.Euler(42, 36, 359); 
		
		this.cam.orthographicSize = 9;
		
		target = TargettoBall; 
		
		StartCoroutine(Changecam());
		
		speedZoom = 9;

    }

 	void Update()
{
		
		
		
    if (Input.GetMouseButtonDown(0))
    {
        if (ZoomIN.HitTest(Input.mousePosition))
        {
		 if (this.cam.orthographicSize >=6)
			this.cam.orthographicSize -= 2;
			Debug.Log (this.cam.orthographicSize);
            //ZoomIn();
        }
        if (ZoomOUT.HitTest(Input.mousePosition))
        {
			if (this.cam.orthographicSize <=14)
				this.cam.orthographicSize += 2;	
				Debug.Log (this.cam.orthographicSize);
				
			
            //ZoomOut();
        }
    }
		
	if (StartLevelMove == true)
		{
			camera.orthographicSize += Time.deltaTime * speedZoom;
			
		
		}
			
//}
//    void LateUpdate()
//
//    {

        //this.cam.orthographicSize -= Input.GetAxis("Mouse ScrollWheel") * scrollSpeed * Time.deltaTime;


        float distance = 30;


 		var go = target.gameObject;
		if (go == null)
		{
  		
		}
		else 
		{
		transform.position = Vector3.Lerp(transform.position, target.transform.position + new Vector3(-distance, distance, -distance), 2.0f * Time.deltaTime);

        this.cam.transform.LookAt(target.transform);
		}
		
		if (camera.orthographicSize <= maxPos)
			speedZoom = 0;
		Debug.Log (speedZoom);
    }
	
	IEnumerator Changecam()
{
	yield return new WaitForSeconds(2.5f);
	camera.orthographicSize -= Time.deltaTime * speedZoom;
	StartLevelMove = false;
    
	//speedZoom = 9;
	//this.cam.orthographicSize = 9;
}

 

    

}

After 2.5 seconds, your code executes the remaining part of the coroutine. The problem is, this is only executed once because you don’t have any loops An example could be:

IEnumerator Changecam()
{
    yield return new WaitForSeconds(2.5f);
    StartLevelMove = false;
    while(camera.orthographicSize > 6){
       camera.orthographicSize -= Time.deltaTime * speedZoom;
       yield return null;
    }
}

Remember to save your project when playing with while loops :slight_smile: