using System.Collections; using System.Collections.Generic; using UnityEngine; public class CamController : MonoBehaviour { public float smoothSpeed; //cameras speed private Vector3 targetPos, newPos; // new camera position public Vector3 minPos, maxPos; // min and max positions of the camera void LateUpdate() { //clamp target position within defined boundaries Vector3 camBoundaryPos = new Vector3( Mathf.Clamp(targetPos.x, minPos.x,maxPos.x), Mathf.Clamp(targetPos.y,minPos.y,maxPos.y), Mathf.Clamp(targetPos.z,minPos.z,maxPos.z) ); newPos = Vector3.Lerp(transform.position, camBoundaryPos, smoothSpeed); //smoothly interpolate the cameras position to the clamped target position transform.position = newPos; //update camera position to new interpolated position } }