93 private float _pitch = 20f;
94 private bool _isDragging;
95 private Vector2 _lastMousePos;
101 void Start() => UpdatePosition();
121 void HandleMouseInput()
123 if (Input.GetMouseButtonDown(0))
126 _lastMousePos = Input.mousePosition;
129 if (Input.GetMouseButtonUp(0))
134 Vector2 delta = (Vector2)Input.mousePosition - _lastMousePos;
138 _lastMousePos = Input.mousePosition;
141 float scroll = Input.GetAxis(
"Mouse ScrollWheel");
142 if (Mathf.Abs(scroll) > 0.001f)
150 void UpdatePosition()
152 if (
target ==
null)
return;
153 Quaternion rotation = Quaternion.Euler(_pitch, _yaw, 0f);
154 transform.position = target.position + rotation * (Vector3.back *
distance);
155 transform.LookAt(
target.position);
Spherical-coordinate camera that orbits around a target Transform.
float minVerticalAngle
Minimum pitch (vertical) angle in degrees.
bool IsAutoRotating
Returns true when auto-rotation is active.
float distance
Current distance from target in world units.
float autoRotateSpeed
Degrees per second of automatic yaw rotation.
void ResetView()
Resets yaw, pitch and distance to their default showcase values.
float maxVerticalAngle
Maximum pitch (vertical) angle in degrees.
float scrollSensitivity
Scroll-wheel zoom sensitivity (world units per scroll unit).
void ToggleAutoRotate()
Flips the auto-rotation state.
float mouseSensitivity
Mouse sensitivity in degrees per pixel-second.
float maxDistance
Farthest allowed distance from the target.
float minDistance
Closest allowed distance to the target.
bool autoRotate
Whether the camera is currently auto-rotating.
Transform target
The point the camera orbits around.