forked from weichx/Deviant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerController.cs
61 lines (50 loc) · 1.96 KB
/
PlayerController.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
using UnityEngine;
public class PlayerController : MonoBehaviour {
private EngineSystem engines;
private FlightControls flightControls;
private WeaponSystem weaponSystem;
public float yawDamp = 0.5f;
public float pitchDamp = 1;
public float rollDamp = 2;
public float startThrottle = 1f;
public Entity target;
private CameraEye cameraEye;
private bool focused = true;
public void Start() {
engines = GetComponent<EngineSystem>();
weaponSystem = GetComponent<WeaponSystem>();
flightControls = new FlightControls(yawDamp, pitchDamp, rollDamp);
engines.SetFlightControls(flightControls);
flightControls.SetStickInputs(0f, 0f, 0f, startThrottle);
EventManager.Instance.AddListener<Event_EntityDespawned>(OnEntityDespawned);
PlayerManager.PlayerEventManager.AddListener<Event_EntityDamaged>(OnDamageTaken);
cameraEye = GetComponentInChildren<CameraEye>();
}
public void Update() {
if(!focused) {
flightControls.SetStickInputs(0f, 0f, 0f, 0f);
return;
}
float x = Input.GetAxis("JoystickX");
float y = Input.GetAxis("JoystickY");
float z = Input.GetAxis("JoystickZ");
float t = (Input.GetAxisRaw("JoystickThrottle") + 1) * 0.5f;
bool fire = Input.GetButton("Fire1");
flightControls.SetStickDamping(yawDamp, pitchDamp, rollDamp);
flightControls.SetStickInputs(x, y, z, t);
if (fire && weaponSystem != null) {
weaponSystem.weaponGroups[0].Fire();
}
}
public void OnApplicationFocus(bool focused) {
this.focused = focused;
}
protected void OnEntityDespawned(Event_EntityDespawned evt) {
if(target == evt.entity) {
EventManager.Instance.TriggerEvent(new Event_PlayerTargetChanged(null, evt.entity));
}
}
protected void OnDamageTaken(Event_EntityDamaged evt) {
cameraEye.Shake(0.05f);
}
}