From 8608d27d67190273bcfad5a4867c3d5faa4c9f6a Mon Sep 17 00:00:00 2001 From: Stedd Date: Sat, 5 Nov 2022 10:43:41 +0100 Subject: [PATCH] Weapon updates *Added feature to switch weapon with scroll wheel *Fixed ammo UI, now updates correctly when changing weapons *Fixed machine gun zoom *Player prefab cleanup --- .../Prefabs/PlayerCapsule.prefab | 14 ++++---- Assets/Weapons/Ammo.cs | 7 +++- Assets/Weapons/MachineGun.prefab | 11 +++--- Assets/Weapons/Weapon.cs | 4 +-- Assets/Weapons/WeaponSwitcher.cs | 35 ++++++++++++++----- 5 files changed, 47 insertions(+), 24 deletions(-) diff --git a/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab b/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab index cb51c1d..a225a0a 100644 --- a/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab +++ b/Assets/ImportedAssets/StarterAssets/FirstPersonController/Prefabs/PlayerCapsule.prefab @@ -9,7 +9,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 2265701993784981172} - - component: {fileID: 9083568455291165773} + - component: {fileID: 7253208606534141378} m_Layer: 8 m_Name: Weapons m_TagString: Untagged @@ -36,7 +36,7 @@ Transform: m_Father: {fileID: 4135013735270702856} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &9083568455291165773 +--- !u!114 &7253208606534141378 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -45,14 +45,11 @@ MonoBehaviour: m_GameObject: {fileID: 160269183453626702} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 01ef216392c8f33409f2efcd91f4e510, type: 3} + m_Script: {fileID: 11500000, guid: 51cf941944fb27e43863c290683f7068, type: 3} m_Name: m_EditorClassIdentifier: - _fpCamera: {fileID: 0} - _muzzleFlash: {fileID: 0} - _bulletImpact: {fileID: 0} - _range: 100 - _weaponDamage: 25 + _weapons: [] + _currentWeapon: 0 --- !u!1 &4135013735270702863 GameObject: m_ObjectHideFlags: 0 @@ -303,6 +300,7 @@ MonoBehaviour: _look: {x: 0, y: 0} _jump: 0 _sprint: 0 + _mouseScale: 0 _analogMovement: 0 _cursorLocked: 1 _cursorInputForLook: 1 diff --git a/Assets/Weapons/Ammo.cs b/Assets/Weapons/Ammo.cs index 4f2b48f..f0ebf60 100644 --- a/Assets/Weapons/Ammo.cs +++ b/Assets/Weapons/Ammo.cs @@ -18,12 +18,17 @@ public class Ammo : MonoBehaviour [SerializeField] private FloatVariable _S_currentBeltAmmoAmount; [SerializeField] private FloatVariable _S_currentMagAmmoAmount; - private void OnEnable() + private void Awake() { _currentBeltAmmoAmount = _maxBeltAmmoAmount; _currentMagAmmoAmount = _maxMagAmmoAmount; } + private void OnEnable() + { + AmmoUpdate(); + } + #region Public Properties public int AmmoType diff --git a/Assets/Weapons/MachineGun.prefab b/Assets/Weapons/MachineGun.prefab index 79338bf..8bb7c1c 100644 --- a/Assets/Weapons/MachineGun.prefab +++ b/Assets/Weapons/MachineGun.prefab @@ -48,13 +48,16 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 01ef216392c8f33409f2efcd91f4e510, type: 3} m_Name: m_EditorClassIdentifier: + _index: 0 _range: 100 _weaponDamage: 4 _timeBetweenShots: 0.1 + _timeBetweenReloads: 0 _fpCamera: {fileID: 0} _muzzleFlash: {fileID: 0} _bulletImpact: {fileID: 252487699782519274, guid: 82851982cb47c134a8403ffcb052b9d2, type: 3} _ammo: {fileID: 5655468185604888337} + _canShoot: 0 --- !u!114 &5655468185604888337 MonoBehaviour: m_ObjectHideFlags: 0 @@ -86,10 +89,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f6b8a4e9bfb741aa96889e5df5a06cba, type: 3} m_Name: m_EditorClassIdentifier: - _fovNormal: 0 - _senseNormal: 0 - _fovZoom: 0 - _senseZoom: 0 + _fovNormal: 40 + _senseNormal: 1 + _fovZoom: 20 + _senseZoom: 0.5 _input: {fileID: 0} _camera: {fileID: 0} _zoomedIn: 0 diff --git a/Assets/Weapons/Weapon.cs b/Assets/Weapons/Weapon.cs index cfa413a..d0a7358 100644 --- a/Assets/Weapons/Weapon.cs +++ b/Assets/Weapons/Weapon.cs @@ -47,7 +47,7 @@ public class Weapon : MonoBehaviour StartCoroutine(Reload()); } - IEnumerator Reload() + private IEnumerator Reload() { _canShoot = false; print($"Reloading {gameObject.name}"); @@ -56,7 +56,7 @@ public class Weapon : MonoBehaviour _canShoot = true; } - IEnumerator Shoot() + private IEnumerator Shoot() { _canShoot = false; if (_ammo.CurrentMagAmmoAmount > 0) diff --git a/Assets/Weapons/WeaponSwitcher.cs b/Assets/Weapons/WeaponSwitcher.cs index 4c53f7e..fcb5c64 100644 --- a/Assets/Weapons/WeaponSwitcher.cs +++ b/Assets/Weapons/WeaponSwitcher.cs @@ -40,38 +40,55 @@ public class WeaponSwitcher : MonoBehaviour private void Update() { + int lastWeapon = _currentWeapon; + + switch (Mouse.current.scroll.ReadValue().y) + { + case > 0: + _currentWeapon++; + break; + case < 0: + _currentWeapon--; + break; + } + if (Mouse.current.middleButton.wasPressedThisFrame) { _currentWeapon++; - if (_currentWeapon > _weapons.Length - 1) - { - _currentWeapon = 0; - } - - SelectWeapon(_currentWeapon); } if (Keyboard.current.digit1Key.wasPressedThisFrame) { _currentWeapon = 0; - SelectWeapon(_currentWeapon); } if (Keyboard.current.digit2Key.wasPressedThisFrame) { _currentWeapon = 1; - SelectWeapon(_currentWeapon); } if (Keyboard.current.digit3Key.wasPressedThisFrame) { _currentWeapon = 2; - SelectWeapon(_currentWeapon); } if (Keyboard.current.digit4Key.wasPressedThisFrame) { _currentWeapon = 3; + } + + if (_currentWeapon > _weapons.Length - 1) + { + _currentWeapon = 0; + } + + if (_currentWeapon < 0) + { + _currentWeapon = _weapons.Length - 1; + } + + if (lastWeapon != _currentWeapon) + { SelectWeapon(_currentWeapon); } }