diff options
author | chai <215380520@qq.com> | 2024-05-23 10:10:23 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:10:23 +0800 |
commit | 81330a6b68d307937c262368a42a3fa4e9ad4207 (patch) | |
tree | 0616a08be385794e062fb616df4ffb503631ee08 /Other/NavMeshTest/Assets/Scripts/CameraController.cs | |
parent | 8722a9920c1f6119bf6e769cba270e63097f8e25 (diff) |
+ NavMeshTest
Diffstat (limited to 'Other/NavMeshTest/Assets/Scripts/CameraController.cs')
-rw-r--r-- | Other/NavMeshTest/Assets/Scripts/CameraController.cs | 66 |
1 files changed, 66 insertions, 0 deletions
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<Camera>(); + } + + 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); + + } + + +} |