using System.Collections; using System.Collections.Generic; using UnityEngine; [RequireComponent(typeof(Camera))] Dont forget to Dellet #yourScriptName and write your Script Name... public class MultipleTargetCamera : MonoBehaviour { public Vector3 offset; public List targets; private Vector3 velocity; public float SmoothTime = 0.5f; public float minZoom = 40f; public float MaxZoom = 10f; public float ZoomLimeter = 50f; private Camera cam; void LateUpdate(){ if(targets.Count == 0) return; Move(); Zoom(); } void Move(){ Vector3 centerPoints = GetCenterPoints(); Vector3 newPosition = centerPoints + offset; transform.position = Vector3.SmoothDamp(transform.position, newPosition, ref velocity, SmoothTime); } void Zoom(){ float newZoom = Mathf.Lerp(MaxZoom, minZoom, GetGraetestDistance() / ZoomLimeter); cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, newZoom, Time.deltaTime); } float GetGraetestDistance(){ var bounds = new Bounds (targets[0].position, Vector3.zero); for (int i = 0; i< targets.Count; i++){ bounds.Encapsulate(targets[i].position); } return bounds.size.x; } Vector3 GetCenterPoints(){ if(targets.Count == 1){ return targets[0].position; } var bounds = new Bounds(targets[0].position, Vector3.zero); for (int i = 0; i(); } // Update is called once per frame void Update() { } }