Fixed Pickup Bug

Pickup weapon that was not in your hand lead to one weapon being "deleted"
0 Rifle (null)
1 Pistole (M92)
2 Hand (Hand)
3 Knife (null)
When u had the "Hand" equipped and picked up another Pistole (e.g. USP), M92 would not be accessable anymore.
ITS NOW FIXED! DAS IST WAS ZÄHLT!
This commit is contained in:
Noah4ever
2021-12-01 13:01:32 +01:00
parent 253b70071f
commit 64cadf0a35
2 changed files with 105 additions and 106 deletions

View File

@@ -41,7 +41,7 @@ public class WeaponManager : NetworkBehaviour
}else if (Input.GetButtonDown("Drop")) { // q Droping weapon
if (activeWeapons[currentWeaponIndex] != null) {
dropWeapon(); // Throws weapon away
dropWeapon(currentWeaponIndex); // Throws weapon away
switchWeapon(1);
activeWeapons[currentWeaponIndex].SetActive(true);
}
@@ -117,8 +117,8 @@ public class WeaponManager : NetworkBehaviour
}
private bool putWeaponInArray(int index, RaycastHit hit) {
if (activeWeapons[currentWeaponIndex] != null) {
dropWeapon(); // Throws weapon away
if (activeWeapons[index] != null) {
dropWeapon(index); // Throws weapon away
}
activeWeapons[index] = hit.transform.gameObject;
activeWeapons[index].SetActive(true);
@@ -131,9 +131,9 @@ public class WeaponManager : NetworkBehaviour
return true;
}
private bool dropWeapon() {
if(currentWeaponIndex != 2) {
GameObject currentWeapon = activeWeapons[currentWeaponIndex];
private bool dropWeapon(int index) {
if(index != 2) {
GameObject currentWeapon = activeWeapons[index];
currentWeapon.SetActive(true);
Rigidbody rigid = currentWeapon.GetComponent<Rigidbody>();
rigid.useGravity = true;
@@ -141,7 +141,7 @@ public class WeaponManager : NetworkBehaviour
rigid.velocity = cam.transform.forward * 10 + cam.transform.up * 2;
currentWeapon.GetComponent<BoxCollider>().enabled = true;
currentWeapon.gameObject.transform.SetParent(null);
activeWeapons[currentWeaponIndex] = null;
activeWeapons[index] = null;
return true;
}