Weapon pickup

+ started pickup weapon script
This commit is contained in:
Noah4ever
2021-11-15 12:53:19 +01:00
parent dac1384e94
commit f9527c17fd
5 changed files with 95 additions and 57 deletions

View File

@@ -7,7 +7,6 @@ using Mirror;
public class WeaponManager : NetworkBehaviour
{
public int currentWeaponIndex = 0;
public List<GameObject> allWeapons = new List<GameObject>();
public GameObject[] activeWeapons;
[SerializeField] Camera cam;
@@ -29,7 +28,6 @@ public class WeaponManager : NetworkBehaviour
else { currentWeaponIndex++; }
}
if (Input.GetButton("Interact")) // e
{
CmdPickupWeapon();
@@ -43,24 +41,24 @@ public class WeaponManager : NetworkBehaviour
[Command]
private void CmdPickupWeapon() {
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
{
Debug.DrawLine(cam.transform.position, hit.point);
if (hit.transform.tag == "Weapon") // If Object is a weapon and the weapon is not in the current active weapons
{
Destroy(hit.transform.gameObject);
switch (hit.transform.GetComponent<Weapon>().WeaponKind.ToString()) // Adding weapon to inventory slot
{
case "Rifle": activeWeapons[0] = hit.transform.gameObject; break;
case "Pistole": activeWeapons[1] = hit.transform.gameObject; break;
case "Knife": activeWeapons[2] = hit.transform.gameObject; break;
case "Granade": activeWeapons[3] = hit.transform.gameObject; break;
case "Grenade": activeWeapons[3] = hit.transform.gameObject; break;
default: break;
}
}
}
}
private bool searchInArray(GameObject[] arr, GameObject searchObj)
private bool isInArray(GameObject[] arr, GameObject searchObj)
{
foreach(GameObject obj in arr)
{