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

@@ -116,9 +116,10 @@ GameObject:
- component: {fileID: 732033708985862910} - component: {fileID: 732033708985862910}
- component: {fileID: 6352645931139448055} - component: {fileID: 6352645931139448055}
- component: {fileID: 5204381087217674634} - component: {fileID: 5204381087217674634}
- component: {fileID: 3937508078766297979}
m_Layer: 0 m_Layer: 0
m_Name: M92 m_Name: M92
m_TagString: Untagged m_TagString: Weapon
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
@@ -177,6 +178,19 @@ MonoBehaviour:
totalAmmunition: 100 totalAmmunition: 100
bulletExit: {fileID: 2236875552107647873} bulletExit: {fileID: 2236875552107647873}
allowAction: 1 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 --- !u!1001 &1330674258901920049
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -483,6 +483,7 @@ GameObject:
- component: {fileID: -7261721819113345487} - component: {fileID: -7261721819113345487}
- component: {fileID: 8957579265169979397} - component: {fileID: 8957579265169979397}
- component: {fileID: 3965891812990671158} - component: {fileID: 3965891812990671158}
- component: {fileID: 8357986889675898169}
m_Layer: 0 m_Layer: 0
m_Name: Player Animation Test m_Name: Player Animation Test
m_TagString: Player m_TagString: Player
@@ -860,6 +861,23 @@ MonoBehaviour:
- m_Rig: {fileID: 8865635171929772803} - m_Rig: {fileID: 8865635171929772803}
m_Active: 1 m_Active: 1
m_Effectors: [] 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 --- !u!1 &6272346181657429393
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1179,10 +1197,18 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: M92 value: M92
objectReference: {fileID: 0} 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} - target: {fileID: 5204381087217674634, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: damage propertyPath: damage
value: 15 value: 15
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 5204381087217674634, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
propertyPath: weaponKind
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bd217f9f85ce78e46a925776562625e8, type: 3} m_SourcePrefab: {fileID: 100100000, guid: bd217f9f85ce78e46a925776562625e8, type: 3}
--- !u!1 &7768205653369755348 stripped --- !u!1 &7768205653369755348 stripped

View File

@@ -6,7 +6,7 @@ public class Weapon : MonoBehaviour
{ {
public enum weaponKinds public enum weaponKinds
{ {
Rifle, Pistole, Knife, Granade Rifle, Pistole, Knife, Grenade
} }
[SerializeField] weaponKinds weaponKind; [SerializeField] weaponKinds weaponKind;
[SerializeField] bool active = false; [SerializeField] bool active = false;

View File

@@ -7,7 +7,6 @@ using Mirror;
public class WeaponManager : NetworkBehaviour public class WeaponManager : NetworkBehaviour
{ {
public int currentWeaponIndex = 0; public int currentWeaponIndex = 0;
public List<GameObject> allWeapons = new List<GameObject>();
public GameObject[] activeWeapons; public GameObject[] activeWeapons;
[SerializeField] Camera cam; [SerializeField] Camera cam;
@@ -29,7 +28,6 @@ public class WeaponManager : NetworkBehaviour
else { currentWeaponIndex++; } else { currentWeaponIndex++; }
} }
if (Input.GetButton("Interact")) // e if (Input.GetButton("Interact")) // e
{ {
CmdPickupWeapon(); CmdPickupWeapon();
@@ -43,24 +41,24 @@ public class WeaponManager : NetworkBehaviour
[Command] [Command]
private void CmdPickupWeapon() { 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 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 switch (hit.transform.GetComponent<Weapon>().WeaponKind.ToString()) // Adding weapon to inventory slot
{ {
case "Rifle": activeWeapons[0] = hit.transform.gameObject; break; case "Rifle": activeWeapons[0] = hit.transform.gameObject; break;
case "Pistole": activeWeapons[1] = hit.transform.gameObject; break; case "Pistole": activeWeapons[1] = hit.transform.gameObject; break;
case "Knife": activeWeapons[2] = 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; default: break;
} }
} }
} }
} }
private bool searchInArray(GameObject[] arr, GameObject searchObj) private bool isInArray(GameObject[] arr, GameObject searchObj)
{ {
foreach(GameObject obj in arr) foreach(GameObject obj in arr)
{ {

View File

@@ -19,7 +19,7 @@ MonoBehaviour:
width: 1536 width: 1536
height: 780.8 height: 780.8
m_ShowMode: 4 m_ShowMode: 4
m_Title: Game m_Title: Hierarchy
m_RootView: {fileID: 2} m_RootView: {fileID: 2}
m_MinSize: {x: 875, y: 300} m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000} m_MaxSize: {x: 10000, y: 10000}
@@ -119,7 +119,7 @@ MonoBehaviour:
m_MinSize: {x: 400, y: 200} m_MinSize: {x: 400, y: 200}
m_MaxSize: {x: 32384, y: 16192} m_MaxSize: {x: 32384, y: 16192}
vertical: 0 vertical: 0
controlID: 87 controlID: 47
--- !u!114 &6 --- !u!114 &6
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 52 m_ObjectHideFlags: 52
@@ -144,7 +144,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 200} m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192} m_MaxSize: {x: 24288, y: 16192}
vertical: 1 vertical: 1
controlID: 88 controlID: 277
--- !u!114 &7 --- !u!114 &7
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 52 m_ObjectHideFlags: 52
@@ -170,7 +170,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 100} m_MinSize: {x: 300, y: 100}
m_MaxSize: {x: 24288, y: 8096} m_MaxSize: {x: 24288, y: 8096}
vertical: 0 vertical: 0
controlID: 89 controlID: 24
--- !u!114 &8 --- !u!114 &8
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 52 m_ObjectHideFlags: 52
@@ -190,8 +190,8 @@ MonoBehaviour:
y: 0 y: 0
width: 243 width: 243
height: 439 height: 439
m_MinSize: {x: 201, y: 221} m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4001, y: 4021} m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 14} m_ActualView: {fileID: 14}
m_Panes: m_Panes:
- {fileID: 14} - {fileID: 14}
@@ -216,8 +216,8 @@ MonoBehaviour:
y: 0 y: 0
width: 493 width: 493
height: 439 height: 439
m_MinSize: {x: 202, y: 221} m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4002, y: 4021} m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 16} m_ActualView: {fileID: 16}
m_Panes: m_Panes:
- {fileID: 15} - {fileID: 15}
@@ -243,8 +243,8 @@ MonoBehaviour:
y: 0 y: 0
width: 533 width: 533
height: 439 height: 439
m_MinSize: {x: 202, y: 221} m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4002, y: 4021} m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 13} m_ActualView: {fileID: 13}
m_Panes: m_Panes:
- {fileID: 13} - {fileID: 13}
@@ -260,7 +260,7 @@ MonoBehaviour:
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 1 m_EditorHideFlags: 1
m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0} m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0}
m_Name: ConsoleWindow m_Name: ProjectBrowser
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Children: [] m_Children: []
m_Position: m_Position:
@@ -269,14 +269,14 @@ MonoBehaviour:
y: 439 y: 439
width: 1269 width: 1269
height: 292 height: 292
m_MinSize: {x: 101, y: 121} m_MinSize: {x: 231, y: 271}
m_MaxSize: {x: 4001, y: 4021} m_MaxSize: {x: 10001, y: 10021}
m_ActualView: {fileID: 18} m_ActualView: {fileID: 17}
m_Panes: m_Panes:
- {fileID: 17} - {fileID: 17}
- {fileID: 18} - {fileID: 18}
m_Selected: 1 m_Selected: 0
m_LastSelected: 0 m_LastSelected: 1
--- !u!114 &12 --- !u!114 &12
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 52 m_ObjectHideFlags: 52
@@ -296,8 +296,8 @@ MonoBehaviour:
y: 0 y: 0
width: 267 width: 267
height: 731 height: 731
m_MinSize: {x: 276, y: 71} m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4001, y: 4021} m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 19} m_ActualView: {fileID: 19}
m_Panes: m_Panes:
- {fileID: 19} - {fileID: 19}
@@ -323,8 +323,8 @@ MonoBehaviour:
m_Tooltip: m_Tooltip:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: -24864 x: 736
y: -25569.6 y: 73.6
width: 531 width: 531
height: 418 height: 418
m_ViewDataDictionary: {fileID: 0} m_ViewDataDictionary: {fileID: 0}
@@ -361,8 +361,8 @@ MonoBehaviour:
m_VAllowExceedBaseRangeMin: 1 m_VAllowExceedBaseRangeMin: 1
m_VAllowExceedBaseRangeMax: 1 m_VAllowExceedBaseRangeMax: 1
m_ScaleWithWindow: 0 m_ScaleWithWindow: 0
m_HSlider: 0 m_HSlider: 1
m_VSlider: 0 m_VSlider: 1
m_IgnoreScrollWheelUntilClicked: 0 m_IgnoreScrollWheelUntilClicked: 0
m_EnableMouseInput: 1 m_EnableMouseInput: 1
m_EnableSliderZoomHorizontal: 0 m_EnableSliderZoomHorizontal: 0
@@ -375,18 +375,18 @@ MonoBehaviour:
y: 21 y: 21
width: 531 width: 531
height: 397 height: 397
m_Scale: {x: 1.2011244, y: 1.2011243} m_Scale: {x: 1.2742728, y: 1.2742728}
m_Translation: {x: 265.5, y: 198.5} m_Translation: {x: 260.34442, y: 200.231}
m_MarginLeft: 0 m_MarginLeft: 0
m_MarginRight: 0 m_MarginRight: 0
m_MarginTop: 0 m_MarginTop: 0
m_MarginBottom: 0 m_MarginBottom: 0
m_LastShownAreaInsideMargins: m_LastShownAreaInsideMargins:
serializedVersion: 2 serializedVersion: 2
x: -221.04288 x: -204.30823
y: -165.26183 y: -157.13354
width: 442.08575 width: 416.70825
height: 330.52365 height: 311.55023
m_MinimalGUI: 1 m_MinimalGUI: 1
m_defaultScale: 1 m_defaultScale: 1
m_LastWindowPixelSize: {x: 663.75, y: 522.5} m_LastWindowPixelSize: {x: 663.75, y: 522.5}
@@ -415,8 +415,8 @@ MonoBehaviour:
m_Tooltip: m_Tooltip:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: -25600 x: 0
y: -25569.6 y: 73.6
width: 242 width: 242
height: 418 height: 418
m_ViewDataDictionary: {fileID: 0} m_ViewDataDictionary: {fileID: 0}
@@ -426,9 +426,9 @@ MonoBehaviour:
m_SceneHierarchy: m_SceneHierarchy:
m_TreeViewState: m_TreeViewState:
scrollPos: {x: 0, y: 0} scrollPos: {x: 0, y: 0}
m_SelectedIDs: 3ef7ffff m_SelectedIDs:
m_LastClickedID: 0 m_LastClickedID: 0
m_ExpandedIDs: 2afbffff m_ExpandedIDs: 5ee1ffffb6e1ffff1ee4ffff2afbffff
m_RenameOverlay: m_RenameOverlay:
m_UserAcceptedRename: 0 m_UserAcceptedRename: 0
m_Name: m_Name:
@@ -536,8 +536,8 @@ MonoBehaviour:
m_Tooltip: m_Tooltip:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: -25356.8 x: 243.2
y: -25569.6 y: 73.6
width: 491 width: 491
height: 418 height: 418
m_ViewDataDictionary: {fileID: 0} m_ViewDataDictionary: {fileID: 0}
@@ -862,7 +862,8 @@ MonoBehaviour:
m_SaveData: [] m_SaveData: []
m_SearchFilter: m_SearchFilter:
m_NameFilter: m_NameFilter:
m_ClassNames: [] m_ClassNames:
- Prefab
m_AssetLabels: [] m_AssetLabels: []
m_AssetBundleNames: [] m_AssetBundleNames: []
m_VersionControlStates: [] m_VersionControlStates: []
@@ -872,8 +873,7 @@ MonoBehaviour:
m_ShowAllHits: 0 m_ShowAllHits: 0
m_SkipHidden: 0 m_SkipHidden: 0
m_SearchArea: 1 m_SearchArea: 1
m_Folders: m_Folders: []
- Assets/Scripts/Weapons
m_Globs: [] m_Globs: []
m_OriginalText: m_OriginalText:
m_ViewMode: 1 m_ViewMode: 1
@@ -885,10 +885,10 @@ MonoBehaviour:
m_LockTracker: m_LockTracker:
m_IsLocked: 0 m_IsLocked: 0
m_FolderTreeState: m_FolderTreeState:
scrollPos: {x: 0, y: 149} scrollPos: {x: 0, y: 0}
m_SelectedIDs: ea630000 m_SelectedIDs: 04ca9a3b
m_LastClickedID: 25578 m_LastClickedID: 1000000004
m_ExpandedIDs: 00000000b8630000ba630000bc630000be630000c0630000 m_ExpandedIDs: 00000000bc630000be630000c0630000c2630000c463000000ca9a3b
m_RenameOverlay: m_RenameOverlay:
m_UserAcceptedRename: 0 m_UserAcceptedRename: 0
m_Name: m_Name:
@@ -916,7 +916,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0} scrollPos: {x: 0, y: 0}
m_SelectedIDs: m_SelectedIDs:
m_LastClickedID: 0 m_LastClickedID: 0
m_ExpandedIDs: 00000000b8630000ba630000bc630000be630000c0630000 m_ExpandedIDs: 00000000bc630000be630000c0630000c2630000c4630000
m_RenameOverlay: m_RenameOverlay:
m_UserAcceptedRename: 0 m_UserAcceptedRename: 0
m_Name: m_Name:
@@ -941,8 +941,8 @@ MonoBehaviour:
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_ResourceFile: m_ResourceFile:
m_ListAreaState: m_ListAreaState:
m_SelectedInstanceIDs: f0650000 m_SelectedInstanceIDs:
m_LastClickedInstanceID: 26096 m_LastClickedInstanceID: 0
m_HadKeyboardFocusLastEvent: 1 m_HadKeyboardFocusLastEvent: 1
m_ExpandedInstanceIDs: c623000030660000986f0000d65e0000 m_ExpandedInstanceIDs: c623000030660000986f0000d65e0000
m_RenameOverlay: m_RenameOverlay:
@@ -992,8 +992,8 @@ MonoBehaviour:
m_Tooltip: m_Tooltip:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: -25600 x: 0
y: -25131.201 y: 512
width: 1268 width: 1268
height: 271 height: 271
m_ViewDataDictionary: {fileID: 0} m_ViewDataDictionary: {fileID: 0}
@@ -1020,8 +1020,8 @@ MonoBehaviour:
m_Tooltip: m_Tooltip:
m_Pos: m_Pos:
serializedVersion: 2 serializedVersion: 2
x: -24331.201 x: 1268.8
y: -25569.6 y: 73.6
width: 266 width: 266
height: 710 height: 710
m_ViewDataDictionary: {fileID: 0} m_ViewDataDictionary: {fileID: 0}
@@ -1031,7 +1031,7 @@ MonoBehaviour:
m_ObjectsLockedBeforeSerialization: [] m_ObjectsLockedBeforeSerialization: []
m_InstanceIDsLockedBeforeSerialization: m_InstanceIDsLockedBeforeSerialization:
m_PreviewResizer: m_PreviewResizer:
m_CachedPref: 160 m_CachedPref: 151
m_ControlHash: -371814159 m_ControlHash: -371814159
m_PrefName: Preview_InspectorPreview m_PrefName: Preview_InspectorPreview
m_LastInspectedObjectInstanceID: -1 m_LastInspectedObjectInstanceID: -1