Magazines

Magazine (Abstract Class)

The Magazine class is an abstract base for implementing various ammo systems such as bullet clips, rechargeable energy units, or custom behavior. It defines the interface and default logic expected from a weapon magazine.

Summary

This component:

  • Tracks clip size and depletion
  • Triggers reload and depletion events
  • Is intended to be extended by subclasses (e.g., BulletMagazine, RechargeableMagazine)

Fields

FieldTypeDescription
clipfloatCurrent number of bullets or units in the clip.
clipSizefloatMaximum allowed bullets or units.
weaponWeaponThe weapon this magazine is attached to.
OnDepletedUnityEventCalled when clip reaches zero.
OnStartReloadUnityEventCalled when a reload begins.
OnReloadCompleteUnityEventCalled when a reload finishes.

Public Methods

MethodDescription
virtual void StartOwner()Override to run setup logic when ownership is assigned (e.g., in multiplayer).
virtual void Reload()Override to implement custom reload logic.
float GetClip()Returns the current clip value.
void ConsumeClip(float amount)Reduces clip by the specified amount.
virtual bool IsDepleted()Checks if clip is empty. If so, triggers OnDepleted.

Inheritance Notes

To implement a custom magazine:

public class BulletMagazine : Magazine
{
    public override void Reload()
    {
        OnStartReload.Invoke();
        clip = clipSize;
        OnReloadComplete.Invoke();
    }
}

Tip

Use UnityEvents like OnDepleted or OnReloadComplete to hook animations or sound effects.

Warning

Calling ConsumeClip() without checking canShoot may cause negative values. Always check state externally.

See Also

Weapon

Barrel

BulletMagazine

RechargeableMagazine