initial commit
This commit is contained in:
58
Assets/Scripts/AmmoPickup.cs
Normal file
58
Assets/Scripts/AmmoPickup.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AmmoPickup : PickupItem
|
||||
{
|
||||
[Header("Ammo Settings")]
|
||||
[SerializeField] private int ammoAmount = 30;
|
||||
[SerializeField] private string targetWeaponName = ""; // Leave blank for currently equipped weapon
|
||||
|
||||
protected override bool CanCollect(GameObject player)
|
||||
{
|
||||
var weaponsController = player.GetComponent<WeaponsController>();
|
||||
if (weaponsController == null)
|
||||
{
|
||||
weaponsController = player.GetComponentInChildren<WeaponsController>();
|
||||
}
|
||||
|
||||
if (weaponsController == null) return false;
|
||||
|
||||
Weapon activeWeapon = weaponsController.ActiveWeapon;
|
||||
if (activeWeapon == null) return false;
|
||||
|
||||
// If target is specified, check if that weapon can receive ammo
|
||||
if (!string.IsNullOrEmpty(targetWeaponName))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Active weapon check: if infinite reserve and current mag full, skip pickup if desired
|
||||
if (activeWeapon.InfiniteReserve)
|
||||
{
|
||||
return activeWeapon.currentAmmo < activeWeapon.maxAmmo;
|
||||
}
|
||||
|
||||
return activeWeapon.CurrentReserveAmmo < activeWeapon.MaxReserveAmmo || activeWeapon.currentAmmo < activeWeapon.maxAmmo;
|
||||
}
|
||||
|
||||
protected override void ApplyPickupEffect(GameObject player)
|
||||
{
|
||||
var weaponsController = player.GetComponent<WeaponsController>();
|
||||
if (weaponsController == null)
|
||||
{
|
||||
weaponsController = player.GetComponentInChildren<WeaponsController>();
|
||||
}
|
||||
|
||||
if (weaponsController != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(targetWeaponName))
|
||||
{
|
||||
weaponsController.AddAmmoToActiveWeapon(ammoAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
weaponsController.AddAmmoToMatchingWeapon(targetWeaponName, ammoAmount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user