using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraScript : MonoBehaviour { //enum CameraState {Idle, ZoomingIn, ZoomedIn, ZoomingOut }; //CameraState currentState; bool isZooming; float time; bool isZoomed; float defaultSize; float targetSize; float startSize; Vector3 DefaultPosition; Vector3 StartPosition; Vector3 targetPosition; Camera myCamera; // Use this for initialization void Awake() { myCamera = GetComponent(); defaultSize = myCamera.orthographicSize; //DefaultPosition = transform.position; } public void GoTo(float zoom, Vector3 CharPos) { isZooming = true; time = 0; //CameraLocation camLocation = CameraLocations.instance.GetLocation(); startSize = myCamera.orthographicSize; targetSize = zoom; StartPosition = transform.position; targetPosition = CharPos; if (!isZoomed) { defaultSize = startSize; DefaultPosition = StartPosition; } isZoomed = true; } public void ZoomOut() { isZooming = true; time = 0; startSize = targetSize; targetSize = defaultSize; //DefaultPosition = StartPosition; StartPosition = targetPosition; targetPosition = DefaultPosition; StartCoroutine(ReachPosition()); } IEnumerator ReachPosition() { while(isZooming) { yield return new WaitForSeconds(0.1f); } isZoomed = false; } // Update is called once per frame void Update() { if (isZooming) { time += Time.deltaTime * 2; myCamera.orthographicSize = Mathf.Lerp(startSize, targetSize, time); transform.position = Vector3.Lerp(StartPosition, targetPosition, time); if (time >= 1) { myCamera.orthographicSize = targetSize; transform.position = targetPosition; isZooming = false; } } } }