-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerInput.cs
86 lines (72 loc) · 2.6 KB
/
PlayerInput.cs
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using UnityEngine;
using System.Collections;
public class PlayerInput : MonoBehaviour {
private CharacterMotor charMot;
private LineOfSight lineOfSight;
private CameraPosition cameraPos;
private Vector3 movDir;
public Vector3 MovDir { get { return movDir; } }
private bool isLooking;
public bool IsLooking { get { return isLooking; } }
// Use this for initialization
void Start () {
charMot = GetComponent<CharacterMotor>();
lineOfSight = GameObject.Find("Main Camera").GetComponent<LineOfSight>();
cameraPos = GameObject.Find("Main Camera").GetComponent<CameraPosition>();
}
// Update is called once per frame
void Update () {
InputHandling();
}
void InputHandling() {
if (charMot != null && charMot.enabled != false) GroundMov();
if (cameraPos != null && cameraPos.enabled != false) CameraControls();
if (charMot != null && charMot.enabled != false) Actions();
if (lineOfSight != null && lineOfSight.enabled != false) DeBugCommands();
}
void GroundMov() {
if (!isLooking) {
float x = 0;
float z = 0;
#region temp alt controls
if (Input.GetKey(KeyCode.LeftArrow)) x = -1;
if (Input.GetKey(KeyCode.RightArrow)) x = 1;
if (Input.GetKey(KeyCode.UpArrow)) z = -1;
if (Input.GetKey(KeyCode.DownArrow)) z = 1;
#endregion
if (Input.GetAxis("Horizontal") != 0) x = Input.GetAxis("Horizontal");
if (Input.GetAxis("Vertical") != 0) z = Input.GetAxis("Vertical");
movDir = new Vector3(x, 0, -z);
if (movDir != Vector3.zero) charMot.Move(movDir);
} else {
movDir = Vector3.zero;
}
}
void CameraControls() { //TEMP KEY!
if (cameraPos.canLook) {
if (Input.GetButton("Action1") || Input.GetKey(KeyCode.X)) {
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
if (Input.GetKey(KeyCode.LeftArrow)) x = -1;
if (Input.GetKey(KeyCode.RightArrow)) x = 1;
if (Input.GetKey(KeyCode.UpArrow)) y = -1;
if (Input.GetKey(KeyCode.DownArrow)) y = 1;
isLooking = true;
cameraPos.LookAround(x, y);
cameraPos.positionTarget = cameraPos.cameraPosFPS;
} else if (Input.GetButtonUp("Action1") || Input.GetKeyUp(KeyCode.X)) {
cameraPos.lookTarget = transform;
cameraPos.positionTarget = cameraPos.cameraPosTop;
lineOfSight.viewMode = LineOfSight.viewModes.VIEW;
isLooking = false;
}
}
}
void Actions() {
}
void DeBugCommands() {
if (Input.GetKeyDown(KeyCode.F1)) lineOfSight.viewMode = LineOfSight.viewModes.VIEW;
if (Input.GetKeyDown(KeyCode.F2)) lineOfSight.viewMode = LineOfSight.viewModes.NOFOG;
if (Input.GetKeyDown(KeyCode.F3)) lineOfSight.viewMode = LineOfSight.viewModes.LIGHTMAP;
}
}