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
Field | Type | Description |
---|---|---|
clip | float | Current number of bullets or units in the clip. |
clipSize | float | Maximum allowed bullets or units. |
weapon | Weapon | The weapon this magazine is attached to. |
OnDepleted | UnityEvent | Called when clip reaches zero. |
OnStartReload | UnityEvent | Called when a reload begins. |
OnReloadComplete | UnityEvent | Called when a reload finishes. |
Public Methods
Method | Description |
---|---|
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.