-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraController.cs
More file actions
62 lines (60 loc) · 2.24 KB
/
CameraController.cs
File metadata and controls
62 lines (60 loc) · 2.24 KB
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
using UnityEngine;
public class CameraController : MonoBehaviour
{
public float panSpeed = 20f;
public float panBorderThickness = 10f;
public float zoomSpeed = 20f;
public float rotationFactor= 10f;
public bool lockCamera = false;
private float mouseX;
private float mouseY;
// Update is called once per frame
void Update(){
Vector3 pos = transform.position;
if (Input.GetKeyUp("space")) {
Debug.Log(lockCamera);
lockCamera = (!lockCamera);
}
if (!lockCamera) {
if(Input.GetKey("w") || Input.mousePosition.y >= Screen.height - panBorderThickness){
pos.z+= panSpeed * Time.deltaTime;
}
if(Input.GetKey("s") || Input.mousePosition.y <= 0 + panBorderThickness){
pos.z-= panSpeed * Time.deltaTime;
}
if(Input.GetKey("d") || Input.mousePosition.x >= Screen.width + panBorderThickness){
pos.x+= panSpeed * Time.deltaTime;
}
if(Input.GetKey("a") || Input.mousePosition.x <= 0 + panBorderThickness){
pos.x-= panSpeed * Time.deltaTime;
}
// Zoom in
if(Input.mouseScrollDelta.y>0){
pos += Vector3.Normalize(transform.forward) *zoomSpeed;
}
// Zoom out
if(Input.mouseScrollDelta.y<0){
pos -= Vector3.Normalize(transform.forward) *zoomSpeed;
}
if(Input.GetKey(KeyCode.LeftAlt) && Input.GetMouseButton(2)){
Debug.Log("yee");
var difference = (mouseX - Input.mousePosition.x)*Time.deltaTime*rotationFactor;
// transform.Rotate(0,difference,0);
Debug.Log(difference);
transform.Rotate(0, difference, 0, Space.World);
}
}
// if(Input.GetKey("s")){
// pos.z-= panSpeed * Time.deltaTime;
// }
// if(Input.GetKey("w")){
// pos.x+= panSpeed * Time.deltaTime;
// }
// if(Input.GetKey("w")){
// pos.x+= panSpeed * Time.deltaTime;
// }
transform.position = pos;
mouseX = Input.mousePosition.x;
mouseY = Input.mousePosition.y;
}
}