blob: 7315615f7cc98d5dcda14e4af3355ddc6390894c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}
}
|