From 81330a6b68d307937c262368a42a3fa4e9ad4207 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 23 May 2024 10:10:23 +0800 Subject: + NavMeshTest --- .../NavMeshTest/Assets/Scripts/CameraController.cs | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Other/NavMeshTest/Assets/Scripts/CameraController.cs (limited to 'Other/NavMeshTest/Assets/Scripts/CameraController.cs') diff --git a/Other/NavMeshTest/Assets/Scripts/CameraController.cs b/Other/NavMeshTest/Assets/Scripts/CameraController.cs new file mode 100644 index 0000000..7315615 --- /dev/null +++ b/Other/NavMeshTest/Assets/Scripts/CameraController.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class CameraController : MonoBehaviour +{ + public float mouseMoveSpeed; + public float aroundSpeed; + public float zoomSpeed; + + private Camera m_Camera; + + private void Awake() + { + m_Camera = GetComponent(); + } + + private void Update() + { + if(Input.GetMouseButton(2)) + { + float mouseX = Input.GetAxis("Mouse X"); + float mouseY = Input.GetAxis("Mouse Y"); + + Vector3 position = transform.position; + + Vector3 forwardDir = Vector3.ProjectOnPlane(transform.forward, Vector3.up).normalized; + + position += forwardDir * Time.unscaledDeltaTime * mouseMoveSpeed * -mouseY; + + position += transform.right * Time.unscaledDeltaTime * mouseMoveSpeed * -mouseX; + + transform.position = position; + } + + if(Input.GetMouseButton(1)) + { + float mouseX = Input.GetAxis("Mouse X"); + float mouseY = Input.GetAxis("Mouse Y"); + + float y = transform.position.y; + + Plane ground = new Plane(Vector3.up, Vector3.zero); + Ray ray = new Ray(transform.position, transform.forward); + float enter; + if(ground.Raycast(ray, out enter)) + { + Vector3 point = transform.position + transform.forward * enter; + + float angle = mouseX * Time.unscaledDeltaTime * aroundSpeed; + transform.RotateAround(point, Vector3.up, angle); + + angle = -mouseY * Time.unscaledDeltaTime * aroundSpeed; + transform.RotateAround(point, transform.right, angle); + } + } + + float scroll = Input.mouseScrollDelta.y; + + m_Camera.orthographicSize = m_Camera.orthographicSize + -scroll * zoomSpeed * Time.unscaledDeltaTime; + m_Camera.orthographicSize = Mathf.Clamp(m_Camera.orthographicSize, 3, 15); + + } + + +} -- cgit v1.1-26-g67d0