mirror of
https://github.com/DerTyp7/defrain-shooter-unity.git
synced 2025-10-29 12:52:07 +01:00
Weapon pickup
+ started pickup weapon script
This commit is contained in:
@@ -116,9 +116,10 @@ GameObject:
|
||||
- component: {fileID: 732033708985862910}
|
||||
- component: {fileID: 6352645931139448055}
|
||||
- component: {fileID: 5204381087217674634}
|
||||
- component: {fileID: 3937508078766297979}
|
||||
m_Layer: 0
|
||||
m_Name: M92
|
||||
m_TagString: Untagged
|
||||
m_TagString: Weapon
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@@ -177,6 +178,19 @@ MonoBehaviour:
|
||||
totalAmmunition: 100
|
||||
bulletExit: {fileID: 2236875552107647873}
|
||||
allowAction: 1
|
||||
--- !u!65 &3937508078766297979
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 5071598280516985511}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 0.034888696, y: 0.17788172, z: 0.26456618}
|
||||
m_Center: {x: 0.009451332, y: -0.07946879, z: -0.26701045}
|
||||
--- !u!1001 &1330674258901920049
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -483,6 +483,7 @@ GameObject:
|
||||
- component: {fileID: -7261721819113345487}
|
||||
- component: {fileID: 8957579265169979397}
|
||||
- component: {fileID: 3965891812990671158}
|
||||
- component: {fileID: 8357986889675898169}
|
||||
m_Layer: 0
|
||||
m_Name: Player Animation Test
|
||||
m_TagString: Player
|
||||
@@ -860,6 +861,23 @@ MonoBehaviour:
|
||||
- m_Rig: {fileID: 8865635171929772803}
|
||||
m_Active: 1
|
||||
m_Effectors: []
|
||||
--- !u!114 &8357986889675898169
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 6272346181302961293}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 98dadd30ba25ec34db3b45d0dca2827b, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
syncMode: 0
|
||||
syncInterval: 0.1
|
||||
currentWeaponIndex: 0
|
||||
activeWeapons: []
|
||||
cam: {fileID: 6272346181657429395}
|
||||
--- !u!1 &6272346181657429393
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1179,10 +1197,18 @@ PrefabInstance:
|
||||
propertyPath: m_Name
|
||||
value: M92
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5071598280516985511, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||
propertyPath: m_TagString
|
||||
value: Weapon
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5204381087217674634, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||
propertyPath: damage
|
||||
value: 15
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5204381087217674634, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||
propertyPath: weaponKind
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
|
||||
--- !u!1 &7768205653369755348 stripped
|
||||
|
||||
@@ -6,7 +6,7 @@ public class Weapon : MonoBehaviour
|
||||
{
|
||||
public enum weaponKinds
|
||||
{
|
||||
Rifle, Pistole, Knife, Granade
|
||||
Rifle, Pistole, Knife, Grenade
|
||||
}
|
||||
[SerializeField] weaponKinds weaponKind;
|
||||
[SerializeField] bool active = false;
|
||||
|
||||
@@ -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