-
Notifications
You must be signed in to change notification settings - Fork 0
/
Actions.cs
80 lines (72 loc) · 2.94 KB
/
Actions.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
using UnityEngine;
using UnityStandardAssets.Characters.FirstPerson;
public class Actions : MonoBehaviour {
public bool PlayerCharacter;
public Camera PlayerCamera;
public GameObject grenade;
public GameObject[] actions;
public GameObject lockHack;
private GameObject currentAction;
private GameObject g;
private AI[] ais;
PlayerGUI playerGUI;
// Use this for initialization
void Start()
{
ais = FindObjectsOfType(typeof(AI)) as AI[];
currentAction = Instantiate(actions[0], transform.position, transform.rotation) as GameObject;
currentAction.transform.parent = PlayerCamera.transform;
currentAction.transform.localPosition = new Vector3(currentAction.transform.localPosition.x + 0.25f, currentAction.transform.localPosition.y + 0.7f, currentAction.transform.localPosition.z + 0.3f);
playerGUI = FindObjectOfType< PlayerGUI > ();
}
// Update is called once per frame
void Update()
{
if ((Input.GetButton("Fire1") || Input.GetAxis ("Fire1") < -0.1) && playerGUI.alive)
{
currentAction.GetComponent<Weapon>().Shoot();
}
if (Input.GetButtonDown("Reload"))
{
currentAction.GetComponent<Weapon>().Reload();
}
if (Input.GetButtonDown("Interact"))
{
RaycastHit hit;
if (Physics.Raycast(PlayerCamera.transform.position, PlayerCamera.transform.forward, out hit))
{
if (Vector3.Distance(hit.collider.transform.position, transform.position) < 5)
{
Ammo a = hit.collider.gameObject.GetComponent<Ammo>();
if (a != null)
{
currentAction.GetComponent<Weapon>().AddAmmo(a.ammo);
if(a.isMissionPickup){
GetComponent<PlayerGUI>().Pickup();
}
a.despawn();
}
Health h = hit.collider.gameObject.GetComponent<Health>();
if (h != null)
{
GetComponent<PlayerGUI>().AddHealth(h.health);
if(h.isMissionPickup){
GetComponent<PlayerGUI>().Pickup();
}
h.despawn();
}
}
}
}
if (Input.GetButtonDown("Grenade"))
{
if (g == null)
{
PlayerPrefs.SetInt ("Shots", PlayerPrefs.GetInt ("Shots") + 1);
g = Instantiate(grenade, new Vector3(PlayerCamera.transform.position.x + 0.5f, PlayerCamera.transform.position.y, PlayerCamera.transform.position.z), PlayerCamera.transform.rotation) as GameObject;
g.GetComponent<Rigidbody>().AddForce(g.transform.forward * 750);
g.GetComponent<Grenade>().SetAI(ais);
}
}
}
}