This commit is contained in:
Noah4ever
2021-10-19 14:36:53 +02:00
parent 631938fa22
commit 3c7a401487
7 changed files with 330 additions and 120 deletions

View File

@@ -12,7 +12,6 @@ GameObject:
- component: {fileID: 4085778817478341875} - component: {fileID: 4085778817478341875}
- component: {fileID: 4085778817478341874} - component: {fileID: 4085778817478341874}
- component: {fileID: 4085778817478341837} - component: {fileID: 4085778817478341837}
- component: {fileID: 4085778817478341836}
m_Layer: 7 m_Layer: 7
m_Name: CrazyWeapon m_Name: CrazyWeapon
m_TagString: Untagged m_TagString: Untagged
@@ -97,22 +96,6 @@ BoxCollider:
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1} m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0} m_Center: {x: 0, y: 0, z: 0}
--- !u!54 &4085778817478341836
Rigidbody:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4085778817478341838}
serializedVersion: 2
m_Mass: 1
m_Drag: 0
m_AngularDrag: 0.05
m_UseGravity: 1
m_IsKinematic: 0
m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!1 &4085778817558063964 --- !u!1 &4085778817558063964
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994} m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1} m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@@ -347,6 +347,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 1995791058} - {fileID: 1995791058}
- {fileID: 1087855705}
m_Father: {fileID: 963194228} m_Father: {fileID: 963194228}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -359,9 +360,15 @@ MonoBehaviour:
m_GameObject: {fileID: 316118901} m_GameObject: {fileID: 316118901}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 430a0b8472192ab42b0101154932f4ad, type: 3} m_Script: {fileID: 11500000, guid: 98dadd30ba25ec34db3b45d0dca2827b, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
currentWeaponIndex: 0
allWeapons:
- {fileID: 1995791057}
- {fileID: 710610056}
activeWeapons: []
cam: {fileID: 963194225}
--- !u!1 &340159597 --- !u!1 &340159597
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -431,7 +438,7 @@ Transform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 340159597} m_GameObject: {fileID: 340159597}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: -0, y: 0.9998384, z: -0, w: -0.01797648}
m_LocalPosition: {x: 1.56, y: 2.88, z: -2.62} m_LocalPosition: {x: 1.56, y: 2.88, z: -2.62}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
@@ -439,7 +446,7 @@ Transform:
- {fileID: 963194228} - {fileID: 963194228}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 182.06, z: 0}
--- !u!1 &450235891 stripped --- !u!1 &450235891 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: -466329591000292508, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3} m_CorrespondingSourceObject: {fileID: -466329591000292508, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
@@ -619,25 +626,30 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 4085778817558063964, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3} m_CorrespondingSourceObject: {fileID: 4085778817558063964, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
m_PrefabInstance: {fileID: 892341459} m_PrefabInstance: {fileID: 892341459}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!95 &710610057 --- !u!114 &710610057
Animator: MonoBehaviour:
serializedVersion: 3
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 710610056} m_GameObject: {fileID: 710610056}
m_Enabled: 1 m_Enabled: 1
m_Avatar: {fileID: 0} m_EditorHideFlags: 0
m_Controller: {fileID: 0} m_Script: {fileID: 11500000, guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e, type: 3}
m_CullingMode: 0 m_Name:
m_UpdateMode: 0 m_EditorClassIdentifier:
m_ApplyRootMotion: 0 weaponKind: 1
m_LinearVelocityBlending: 0 active: 0
m_WarningMessage: damage: 0
m_HasTransformHierarchy: 1 firerate: 0
m_AllowConstantClipSamplingOptimization: 1 recoilStrength: 0
m_KeepAnimatorControllerStateOnDisable: 0 currentAmmunition: 0
magazinSize: 0
totalAmmunition: 0
flash: {fileID: 1447530107}
smoke: {fileID: 1458153373}
bulletExit: {fileID: 964267714}
cam: {fileID: 963194225}
--- !u!54 &710610058 --- !u!54 &710610058
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -968,6 +980,30 @@ PrefabInstance:
propertyPath: m_Layer propertyPath: m_Layer
value: 6 value: 6
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_LocalPosition.x
value: 1.02
objectReference: {fileID: 0}
- target: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_LocalPosition.y
value: 2.9450002
objectReference: {fileID: 0}
- target: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_LocalPosition.z
value: -1.97
objectReference: {fileID: 0}
- target: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9566878
objectReference: {fileID: 0}
- target: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_LocalRotation.y
value: 0.29111606
objectReference: {fileID: 0}
- target: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 33.85
objectReference: {fileID: 0}
- target: {fileID: 4085778817558063964, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3} - target: {fileID: 4085778817558063964, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
propertyPath: m_Name propertyPath: m_Name
value: Weapon1 value: Weapon1
@@ -1020,8 +1056,7 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z propertyPath: m_LocalEulerAnglesHint.z
value: 0 value: 0
objectReference: {fileID: 0} objectReference: {fileID: 0}
m_RemovedComponents: m_RemovedComponents: []
- {fileID: 4085778817478341836, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3} m_SourcePrefab: {fileID: 100100000, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
--- !u!1 &963194225 --- !u!1 &963194225
GameObject: GameObject:
@@ -1189,6 +1224,37 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 0 m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1087855704
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1087855705}
m_Layer: 7
m_Name: Hammer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1087855705
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1087855704}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1308256818}
m_Father: {fileID: 316118902}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1111479331 stripped --- !u!1 &1111479331 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 2550463727306718371, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3} m_CorrespondingSourceObject: {fileID: 2550463727306718371, guid: 823e8b39d52b71b4eb5a91dbc8d6d59e, type: 3}
@@ -1459,6 +1525,102 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1308256817
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1308256818}
- component: {fileID: 1308256821}
- component: {fileID: 1308256820}
- component: {fileID: 1308256819}
m_Layer: 7
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1308256818
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1308256817}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.052215002, y: 0.42723, z: 0.089824274}
m_Children: []
m_Father: {fileID: 1087855705}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!65 &1308256819
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1308256817}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!23 &1308256820
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1308256817}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &1308256821
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1308256817}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1447530104 --- !u!1 &1447530104
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -21391,28 +21553,25 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3} m_CorrespondingSourceObject: {fileID: 4085778817478341839, guid: decdb19fa1f98b14fb2639db82e266c8, type: 3}
m_PrefabInstance: {fileID: 892341459} m_PrefabInstance: {fileID: 892341459}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!114 &1946722407 --- !u!95 &1946722411
MonoBehaviour: Animator:
serializedVersion: 3
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1946722405} m_GameObject: {fileID: 1946722405}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_Avatar: {fileID: 0}
m_Script: {fileID: 11500000, guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e, type: 3} m_Controller: {fileID: 0}
m_Name: m_CullingMode: 0
m_EditorClassIdentifier: m_UpdateMode: 0
active: 0 m_ApplyRootMotion: 0
damage: 0 m_LinearVelocityBlending: 0
firerate: 0 m_WarningMessage:
recoilStrength: 0 m_HasTransformHierarchy: 1
currentAmmunition: 0 m_AllowConstantClipSamplingOptimization: 1
totalAmmunition: 0 m_KeepAnimatorControllerStateOnDisable: 0
flash: {fileID: 1447530107}
smoke: {fileID: 1458153373}
bulletExit: {fileID: 964267714}
camera: {fileID: 963194225}
--- !u!1 &1960893053 --- !u!1 &1960893053
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -21703,16 +21862,18 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e, type: 3} m_Script: {fileID: 11500000, guid: c98f5c47a8b7dd64f86fd6f42c4d6e5e, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
weaponKind: 0
active: 1 active: 1
damage: 20 damage: 20
firerate: 0.2 firerate: 0.2
recoilStrength: 15 recoilStrength: 15
currentAmmunition: 12 currentAmmunition: 10
totalAmmunition: 12 magazinSize: 12
totalAmmunition: 24
flash: {fileID: 1869164905} flash: {fileID: 1869164905}
smoke: {fileID: 1612241555} smoke: {fileID: 1612241555}
bulletExit: {fileID: 964267714} bulletExit: {fileID: 964267714}
camera: {fileID: 963194225} cam: {fileID: 963194225}
--- !u!95 &1995791060 --- !u!95 &1995791060
Animator: Animator:
serializedVersion: 3 serializedVersion: 3
@@ -21870,7 +22031,7 @@ Transform:
m_GameObject: {fileID: 2125254906} m_GameObject: {fileID: 2125254906}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 0.35526}
m_Children: [] m_Children: []
m_Father: {fileID: 963194228} m_Father: {fileID: 963194228}
m_RootOrder: 0 m_RootOrder: 0

View File

@@ -4,43 +4,36 @@ using UnityEngine;
public class Weapon : MonoBehaviour public class Weapon : MonoBehaviour
{ {
public enum weaponKinds
{
Rifle, Pistole, Knife, Granade
}
[SerializeField] weaponKinds weaponKind;
[SerializeField] bool active = false; [SerializeField] bool active = false;
[SerializeField] float damage = 0; [SerializeField] float damage = 0;
[SerializeField] float firerate = 0; [SerializeField] float firerate = 0;
[SerializeField] float recoilStrength = 0; [SerializeField] float recoilStrength = 0;
[SerializeField] int currentAmmunition = 0; [SerializeField] int currentAmmunition = 0;
[SerializeField] int magazinSize = 0;
[SerializeField] int totalAmmunition = 0; [SerializeField] int totalAmmunition = 0;
[SerializeField] ParticleSystem flash; [SerializeField] ParticleSystem flash;
[SerializeField] ParticleSystem smoke; [SerializeField] ParticleSystem smoke;
[SerializeField] GameObject bulletExit; [SerializeField] GameObject bulletExit;
[SerializeField] GameObject camera; [SerializeField] GameObject cam;
[SerializeField] GameObject model;
private bool allowShoot = true, isReloading = false;
public bool Active { get => active; set => active = value; } public bool Active { get => active; set => active = value; }
public weaponKinds WeaponKind { get => weaponKind; set => weaponKind = value; }
private bool allowShoot = true, isShooting = false;
Animator anim; //Animator anim;
/*
*
* + Weapon Pickup
* + Weapon Manage
* + Weapon Inventory
* + Weapon Drop
*
*
*/
private void Start() private void Start()
{ {
anim = GetComponent<Animator>(); //anim = GetComponent<Animator>();
currentAmmunition = magazinSize;
if (Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit)) if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit)) // Not Working
{ {
transform.rotation = Quaternion.Euler(0f, hit.point.y, 0f); transform.rotation = Quaternion.Euler(0f, hit.point.y, 0f);
} }
@@ -49,34 +42,32 @@ public class Weapon : MonoBehaviour
{ {
if (Input.GetButton("Fire") && allowShoot && currentAmmunition > 0) if (Input.GetButton("Fire") && allowShoot && currentAmmunition > 0)
{ {
anim.Play("USP_Shooting"); //anim.Play("USP_Shooting");
isShooting = true;
StartCoroutine(fireRate()); StartCoroutine(fireRate());
fire(); fire();
currentAmmunition--; currentAmmunition--;
} }
else
{
isShooting = false;
}
if (Input.GetButton("Reload")) if (Input.GetButton("Reload"))
{ {
currentAmmunition = totalAmmunition; if (isReloading == false && totalAmmunition > 0)
{
isReloading = true;
int dif = magazinSize - currentAmmunition;
if(totalAmmunition >= dif) {
currentAmmunition += dif;
totalAmmunition -= dif;
}
else{
currentAmmunition += totalAmmunition;
totalAmmunition = 0;
}
isReloading = false;
}
} }
if (Input.GetButton("Aim")) // Not working properly, maybe Animations are not correct to use if (Input.GetButton("Aim")) // Not working properly, maybe Animations are not correct to use
{ {
anim.Play("USP_Aim"); //anim.Play("USP_Aim");
}
if (Input.GetButton("Interact"))
{
if(Physics.Raycast(camera.transform.position, camera.transform.forward, out RaycastHit hit))
{
Debug.DrawLine(camera.transform.position, hit.point);
if (hit.collider.transform.name == transform.name)
{
Debug.Log("Hit me!");
}
}
} }
} }

View File

@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponManager : MonoBehaviour
{
public int currentWeaponIndex = 0;
public List<GameObject> allWeapons = new List<GameObject>();
public GameObject[] activeWeapons;
[SerializeField] GameObject cam;
private void Awake()
{
activeWeapons = new GameObject[4];
}
void Update() {
if(Input.GetAxis("Mouse ScrollWheel") > 0f){ // Scroll up
if (currentWeaponIndex <= 0)
{ currentWeaponIndex = activeWeapons.Length; }
else { currentWeaponIndex--; }
}
if (Input.GetAxis("Mouse ScrollWheel") < 0f){ // Scroll down
if (currentWeaponIndex >= activeWeapons.Length)
{ currentWeaponIndex = 0; }
else { currentWeaponIndex++; }
}
if (Input.GetButton("Interact")) // e
{
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out RaycastHit hit))
{
Debug.DrawLine(cam.transform.position, hit.point);
if (allWeapons.Contains(hit.transform.gameObject) && !searchInArray(activeWeapons, hit.transform.gameObject)) // If Object is a weapon and the weapon is not in the current active weapons
{
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;
default: break;
}
}
}
}
if (Input.GetButton("Drop")) // q Droping weapon
{
activeWeapons[currentWeaponIndex] = null;
}
}
private bool searchInArray(GameObject[] arr, GameObject searchObj)
{
foreach(GameObject obj in arr)
{
if (obj == searchObj) return true;
}
return false;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 430a0b8472192ab42b0101154932f4ad guid: 98dadd30ba25ec34db3b45d0dca2827b
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -1,20 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WeaponSwitch : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -341,3 +341,35 @@ InputManager:
type: 0 type: 0
axis: 0 axis: 0
joyNum: 0 joyNum: 0
- serializedVersion: 3
m_Name: Drop
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: q
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Pickup
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: e
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0