-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventory.cs
91 lines (72 loc) · 2.59 KB
/
Inventory.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
87
88
89
90
91
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Inventory : MonoBehaviour
{
public static int currentWeapon = -1;
public static bool droppedWeapon = false;
public GameObject weaponSet;
GameObject spawnPosition;
GameObject hand;
public GameObject[] weapons = new GameObject[10];
public Sprite[] iconWeapons = new Sprite[11];
public Image weaponsHUD;
public void SetWeapon () {
if (currentWeapon != -1) {
Destroy (weaponSet);
weaponSet = Instantiate(weapons[currentWeapon], spawnPosition.transform.position, spawnPosition.transform.rotation) as GameObject;
weaponSet.transform.parent = hand.transform;
weaponSet.rigidbody.useGravity = false;
weaponSet.rigidbody.constraints = RigidbodyConstraints.FreezeAll;
weaponSet.rigidbody.isKinematic = true;
weaponSet.rigidbody.mass = 1;
weaponSet.rigidbody.interpolation = RigidbodyInterpolation.None;
if (currentWeapon == 0 || currentWeapon == 1)
weaponSet.GetComponent<BoxCollider>().enabled = false;
if (currentWeapon == 8) {
weaponSet.GetComponent<CapsuleCollider>().enabled = false;
weaponSet.GetComponent<SphereCollider>().enabled = false;
}
}else
Destroy (weaponSet);
weaponsHUD = GameObject.Find ("/Canvas/HUD/Weapon HUD").GetComponent<Image>();
}
void DropWeapon () {
if (weaponSet != null && Player.droppedWeapon == true) {
Destroy (weaponSet);
Instantiate(weapons[currentWeapon], spawnPosition.transform.position, spawnPosition.transform.rotation);
currentWeapon = -1;
}
}
// Use this for initialization
void Start () {
spawnPosition = GameObject.Find("/Hercules/python/hips/spine/spine-1/chest/chest-1/clavicle_R/deltoid_R/upper_arm_R/forearm_R/hand_R/PositionWeapon");
hand = GameObject.Find("/Hercules/python/hips/spine/spine-1/chest/chest-1/clavicle_R/deltoid_R/upper_arm_R/forearm_R/hand_R");
}
// Update is called once per frame
void Update () {
if (Player.attacked == true && currentWeapon == 0) {
Instantiate(weapons[currentWeapon +9], spawnPosition.transform.position, spawnPosition.transform.rotation);
Player.attacked = false;
}
if (weaponSet != null) weaponSet.rigidbody.position = Vector3.zero;
DropWeapon ();
weaponsHUD.sprite = iconWeapons[currentWeapon +1];
if (Input.GetKeyDown(KeyCode.Alpha0)) {
currentWeapon = -1;
SetWeapon ();
}
if (Input.GetKeyDown(KeyCode.Alpha1)) {
currentWeapon = 0;
SetWeapon ();
}
if (Input.GetKeyDown(KeyCode.Alpha2)) {
currentWeapon = 1;
SetWeapon ();
}
if (Input.GetKeyDown(KeyCode.Alpha9)) {
currentWeapon = 8;
SetWeapon ();
}
}
}