aboutsummaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorWeicao-CatilGrass <1992414357@qq.com>2026-05-22 11:32:02 +0800
committerWeicao-CatilGrass <1992414357@qq.com>2026-05-22 11:32:02 +0800
commite36406960cc364dac38e462fe93702884ae7351d (patch)
tree5281e325e2e59ec9194518445f8588a8c5d807df /Assets/Scripts
parent8691bc52a6721ce38327a3000309c6b0b7c78256 (diff)
增加鼠标锁定
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/CameraHandler.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/Assets/Scripts/CameraHandler.cs b/Assets/Scripts/CameraHandler.cs
index 38ab888..b0b8a70 100644
--- a/Assets/Scripts/CameraHandler.cs
+++ b/Assets/Scripts/CameraHandler.cs
@@ -16,6 +16,8 @@ namespace DS
private LayerMask _ignoreLayers;
private Vector3 cameraFollowVelocity = Vector3.zero;
+ private bool _cursorLocked = false;
+
public static CameraHandler singleton;
public float lookSpeed = 0.1f;
public float followSpeed = 0.1f;
@@ -40,6 +42,28 @@ namespace DS
_ignoreLayers = ~(1 << 8 | 1 << 9 | 1 << 10);
}
+ private void Update()
+ {
+ UpdateCursorLock();
+ }
+
+ private void UpdateCursorLock()
+ {
+ if (Input.GetMouseButtonDown(0))
+ {
+ Cursor.lockState = CursorLockMode.Locked;
+ Cursor.visible = false;
+ _cursorLocked = true;
+ }
+
+ if (Input.GetKeyDown(KeyCode.Escape))
+ {
+ Cursor.lockState = CursorLockMode.None;
+ Cursor.visible = true;
+ _cursorLocked = false;
+ }
+ }
+
public void FollowTarget(float delta)
{
Vector3 targetPosition = Vector3.SmoothDamp(_myTransform.position, targetTransform.position,
@@ -51,6 +75,9 @@ namespace DS
public void HandleCameraRotation(float delta, float mouseInputX, float mouseInputY)
{
+ if (!_cursorLocked)
+ return;
+
_lookAngle += (mouseInputX * lookSpeed) / delta;
_pivotAngle -= (mouseInputY * pivotSpeed) / delta;
_pivotAngle = Mathf.Clamp(_pivotAngle, minimumPivot, maximumPivot);