From 593fe9e0bf920bbebd86847ea8aeb38a17bc3212 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 13 Jan 2025 11:55:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=B8=E6=9C=BA=E8=B7=B3?= =?UTF-8?q?=E8=B7=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/FreeCameraController.cs | 36 ++++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/FreeCameraController.cs b/Assets/Scripts/FreeCameraController.cs index 89c40a15..d0072685 100644 --- a/Assets/Scripts/FreeCameraController.cs +++ b/Assets/Scripts/FreeCameraController.cs @@ -22,6 +22,7 @@ public class FreeCameraController : MonoBehaviour private float yRotation = 0.0f; public bool isMov = true; public bool isRot = true; + private void Awake() { instance = this; @@ -32,7 +33,7 @@ public class FreeCameraController : MonoBehaviour void Update() { - if (isMov == true) + if (isMov) { // ƶ float horizontal = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime; @@ -58,7 +59,6 @@ public class FreeCameraController : MonoBehaviour { // ת - Vector3 mouseDelta = Input.mousePosition - lastMousePosition; // תֵ lastMousePosition = Input.mousePosition; @@ -68,8 +68,8 @@ public class FreeCameraController : MonoBehaviour // X תΧ xRotation = Mathf.Clamp(xRotation, -xRotationLimit, xRotationLimit); - //// Y תΧ - //if (minRotationLimitY!=-1&&maxRotationLimitY!=-1) + // Y תΧ + //if (minRotationLimitY != -1 && maxRotationLimitY != -1) //{ // yRotation = Mathf.Clamp(yRotation, minRotationLimitY, maxRotationLimitY); //} @@ -77,10 +77,6 @@ public class FreeCameraController : MonoBehaviour transform.rotation = Quaternion.Euler(xRotation, yRotation, 0); } } - - - - } // תָ @@ -102,9 +98,27 @@ public class FreeCameraController : MonoBehaviour Vector3 currentRotation = transform.eulerAngles; xRotation = currentRotation.x; yRotation = currentRotation.y; - transform.eulerAngles = currentRotation; - //minRotationLimitY = currentRotation.y - yRotationLimit / 2; - //maxRotationLimitY = currentRotation.y + yRotationLimit / 2; + + // һ xRotation yRotation + if (xRotation > 180f) + { + xRotation -= 360f; + } + else if (xRotation < -180f) + { + xRotation += 360f; + } + + if (yRotation > 180f) + { + yRotation -= 360f; + } + else if (yRotation < -180f) + { + yRotation += 360f; + } + + transform.eulerAngles = new Vector3(xRotation, yRotation, 0); } public void SetLock(bool isMov, bool isRot)