added inventory and stamina system
This commit is contained in:
@@ -16,6 +16,8 @@ public class SimpleGun : MonoBehaviour
|
||||
public float recoilRecoverySpeed = 12f;
|
||||
|
||||
[Header("Weapon Bob Settings")]
|
||||
[Tooltip("Set false if WeaponBob component is on the Camera — they'll double-stack otherwise.")]
|
||||
public bool enableInternalBob = false;
|
||||
public float bobFrequency = 10f;
|
||||
public float bobHorizontalAmplitude = 0.05f;
|
||||
public float bobVerticalAmplitude = 0.03f;
|
||||
@@ -48,6 +50,10 @@ public class SimpleGun : MonoBehaviour
|
||||
// Fire timing
|
||||
private float nextTimeToFire = 0f;
|
||||
|
||||
// Cached refs for inventory check
|
||||
private Inventory _inventory;
|
||||
private WeaponManager _weaponManager;
|
||||
|
||||
void Start()
|
||||
{
|
||||
currentAmmo = maxAmmo;
|
||||
@@ -58,7 +64,12 @@ public class SimpleGun : MonoBehaviour
|
||||
fpsCam = GetComponentInParent<Camera>();
|
||||
|
||||
playerController = GetComponentInParent<CharacterController>();
|
||||
originalLocalPos = transform.localPosition;
|
||||
_inventory = GetComponentInParent<Inventory>();
|
||||
_weaponManager = GetComponentInParent<WeaponManager>();
|
||||
// originalLocalPos is driven by WeaponManager's offset — don't cache here
|
||||
originalLocalPos = _weaponManager != null
|
||||
? _weaponManager.weaponPositionOffset
|
||||
: transform.localPosition;
|
||||
|
||||
|
||||
// NUCLEAR OPTION: Remove ANY collider on this object or children
|
||||
@@ -93,6 +104,10 @@ public class SimpleGun : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Don't shoot while the inventory is open
|
||||
bool inventoryOpen = _inventory != null && _inventory.IsOpen;
|
||||
if (inventoryOpen) return;
|
||||
|
||||
// Shooting
|
||||
if (isAutomatic ? InputData.leftMouseButton.down : InputData.leftMouseButton.pressed)
|
||||
{
|
||||
@@ -107,11 +122,18 @@ public class SimpleGun : MonoBehaviour
|
||||
if (InputData.reload.pressed)
|
||||
Reload();
|
||||
|
||||
// Keep base position in sync with WeaponManager's live offset
|
||||
if (_weaponManager != null)
|
||||
originalLocalPos = _weaponManager.weaponPositionOffset;
|
||||
|
||||
// Recover from recoil
|
||||
recoilOffset = Vector3.Lerp(recoilOffset, Vector3.zero, Time.deltaTime * recoilRecoverySpeed);
|
||||
|
||||
// Weapon bob
|
||||
UpdateBob();
|
||||
// Weapon bob (only if internal bob is enabled — disable if WeaponBob is on the Camera)
|
||||
if (enableInternalBob)
|
||||
UpdateBob();
|
||||
else
|
||||
bobOffset = Vector3.zero;
|
||||
|
||||
// Apply combined position: original + recoil + bob
|
||||
transform.localPosition = originalLocalPos + recoilOffset + bobOffset;
|
||||
|
||||
Reference in New Issue
Block a user