mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 20:52:10 +01:00
Weapon pickup
+ started pickup weapon script
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user