summaryrefslogtreecommitdiff
path: root/Other/NavMeshTest/Assets/Scripts/CameraController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Other/NavMeshTest/Assets/Scripts/CameraController.cs')
-rw-r--r--Other/NavMeshTest/Assets/Scripts/CameraController.cs66
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);
+
+ }
+
+
+}