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
This commit is contained in:
Stedd 2022-11-05 10:43:41 +01:00
parent e8b0617dbb
commit 8608d27d67
5 changed files with 47 additions and 24 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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);
}
}