using UnityEngine; public class MouseOrbitCS : MonoBehaviour { public Transform target; public float distance = 10f; public float xSpeed = 250f; public float ySpeed = 120f; public float yMinLimit = -20f; public float yMaxLimit = 80f; private float x; private float y; private float normal_angle; private void Start() { Vector3 eulerAngles = base.transform.eulerAngles; x = eulerAngles.y; y = eulerAngles.x; } private void LateUpdate() { if ((bool)target && !Input.GetKey(KeyCode.F)) { if (!Input.GetMouseButton(0)) { x += Input.GetAxis("Mouse X") * xSpeed * 0.02f; y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02f; } y = ClampAngle(y, yMinLimit + normal_angle, yMaxLimit + normal_angle); Quaternion quaternion = Quaternion.Euler(y, x, 0f); Vector3 position = quaternion * new Vector3(0f, 0f, 0f - distance) + target.position; base.transform.rotation = quaternion; base.transform.position = position; } } private static float ClampAngle(float angle, float min, float max) { if (angle < -360f) { angle += 360f; } if (angle > 360f) { angle -= 360f; } return Mathf.Clamp(angle, min, max); } public void set_normal_angle(float a) { normal_angle = a; } }