void PanCamera(Vector3 newPanPosition) { if (_gridModel.AreUnitsInteracting()) { return; } // Determine how much to move the camera Vector3 offset = cam.ScreenToViewportPoint(lastPanPosition - newPanPosition); Vector3 move = new Vector3(offset.x * PanSpeed, 0, offset.y * PanSpeed); // Perform the movement transform.Translate(move, Space.World); // Ensure the camera remains within bounds. Vector3 pos = transform.position; pos.x = Mathf.Clamp(transform.position.x, BoundsX[0], BoundsX[1]); pos.z = Mathf.Clamp(transform.position.z, BoundsZ[0], BoundsZ[1]); transform.position = pos; // Cache the position lastPanPosition = newPanPosition; }