added inventory and stamina system

This commit is contained in:
2026-02-17 15:38:46 +00:00
parent 8b975163a0
commit 27f2931ce1
43 changed files with 2980 additions and 250 deletions

View File

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