Weapon Component

The Weapon script is the brain of your weapon prefab. It is recommend to place it on the root GameObject of the weapon. Its primary responsibilities are:

  • Handling player input
  • Managing the weapon’s firing state
  • Connecting to other components like barrels and recoil objects
  • Broadcasting events like equip and holster
  • configuring the equip time

⚙️ Inspector Overview

Here’s a breakdown of each field:

Weapon Script Inspector

Barrel

A reference to the barrel component (e.g., RaycastBarrel). This tells the weapon which barrel to use when firing.

Recoil

Reference to the Recoil GameObject. Used to apply visual and functional recoil when the weapon is fired.

Config

Equip Time

Time in seconds before the weapon is fully equipped and ready to fire.

OnEquiped (UnityEvent)

This event is invoked when the weapon has finished equipping. You can use it to trigger animations, sounds, or logic.

Tip

Use this to hook animations, sounds, VFX in the inspector

OnHolster (UnityEvent)

This event is triggered when the weapon is holstered. Use it for hiding the weapon, stopping effects, etc.

Tip

Use this to hook or trigger animations, sounds, VFX in the inspector as well

Shoot State

Shows the current state of the weapon. This is useful for debugging and includes states like:

  • Resting
  • Shooting
  • Reloading

Note

This is internal to for the barrel and magazine know what’s the state of the weapon

💡 Usage Tips

  • Place this script on the root GameObject of your weapon prefab.
  • Make sure to assign a barrel and optionally recoil components for the weapon to function.
  • Use UnityEvents to easily hook up animation or sound triggers without modifying code.

✅ Required For

✅ Functional shooting
✅ Input management
✅ State transitions
✅ Recoil interaction
✅ Barrel connection