using UnityEngine; using Cinemachine; public class EdgePanningController: MonoBehaviour { public CinemachineFreeLook virtualCamera; private CinemachineCameraOffset cameraOffset; public float edgeThreshold = 50f; // Edge detection distance public float panSpeed = 0.1f; // How much to offset per frame private Vector3 defaultOffset; private void Start() { cameraOffset = virtualCamera.GetComponent(); defaultOffset = cameraOffset.m_Offset; // Store default offset } private void Update() { Vector3 newOffset = defaultOffset; Vector3 mousePos = Input.mousePosition; float screenWidth = Screen.width; float screenHeight = Screen.height; // Left Edge if (mousePos.x <= edgeThreshold) newOffset.x -= panSpeed; // Right Edge if (mousePos.x >= screenWidth - edgeThreshold) newOffset.x += panSpeed; // Bottom Edge if (mousePos.y <= edgeThreshold) newOffset.y -= panSpeed; // Top Edge if (mousePos.y >= screenHeight - edgeThreshold) newOffset.y += panSpeed; // Smooth transition cameraOffset.m_Offset = Vector3.Lerp(cameraOffset.m_Offset, newOffset, Time.deltaTime * 5f); } }