IEnumerator CameraLerp(KCam fromCam, KCam toCam, float time) { inTransition = true; toCam.SetActive(true); float lerpTime = 0; while (lerpTime < time) { float t = lerpTime / time; mainCamera.transform.position = Vector3.Lerp(fromCam.transform.position, toCam.transform.position, t); mainCamera.transform.rotation = Quaternion.Lerp(fromCam.transform.rotation, toCam.transform.rotation, t); mainCamera.fieldOfView = Mathf.Lerp(fromCam.camera.fieldOfView, toCam.camera.fieldOfView, t); mainCamera.aspect = Mathf.Lerp(fromCam.camera.aspect, toCam.camera.aspect, t); lerpTime += Time.deltaTime; yield return(null); } mainCamera.transform.SetParent(toCam.transform, false); mainCamera.CopyFrom(toCam.camera); activeCam = toCam; if (fromCam != toCam) { fromCam.SetActive(false); } inTransition = false; }
public void RegisterCamera(string tag, KCam cam) { cameras.Add(tag, cam); camList.Add(cam); cam.camera.enabled = false; cam.SetActive(false); }