blob: 40c2fb28e5394649430a964f56fa6d993dc0ae75 (
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
|
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;
}
}
|