Initialization
To begin setting up a weapon using the Modular Weapon System, you’ll first need to create the weapon prefab in your Unity scene.
🧱 Create the Weapon Root
- In the Hierarchy, right-click and create an empty
GameObject
. - Rename it to match the weapon you’re building (e.g.,
Pistol
).
ℹ️
This object will hold the
Weapon
script and serve as the entry point for all other modules.🎯 Add a Recoil Handler
If you want your weapon to have recoil behavior:
- Right-click your weapon root and create a child GameObject.
- Name it
Recoil
. - Set its Position and Rotation to
0,0,0
to center it properly.
ℹ️
This object will act as a pivot point for applying recoil movement.
🔗 Attach the Weapon Model
- Drag and drop your weapon model (e.g., a 3D pistol) as a child of the
Recoil
GameObject.
⚠️
If you don’t want to use recoil, just add it as child of the root
- This structure allows the recoil object to apply movement to the visual mesh without affecting the weapon’s logic or transform root.
Your hierarchy should now look like this:
➕ Add the Weapon Component
- Select the root of the gameobject
- Add the Weapon component as following
💾 Save Prefab
- Drag and drop the
root gameobject
into your project to create aprefab
⏭️ Next Step
Let’s add next a barrel to our pistol to enable it to shoot bullets