Getting Started
๐ง How It Works
A weapon is a few small components on one prefab:
flowchart LR
A[Weapon] -->|trigger| B(Barrel)
B -->|asks for ammo| C(Magazine)
B -->|shots| D[Hitbox and Health]
B -->|events| E(Recoil, sounds, effects)
- Weapon reads the trigger (its own input or your calls) and holds the barrel and the magazine.
- Barrel decides how a shot travels: raycast, shotgun, projectile or laser. Its Config holds the fire rate, damage and bullets per shot.
- Barrel modifiers change when the barrel fires:
FiringMode(semi, burst, full auto) andSpool(wind-up and wind-down). - Magazine holds the ammo: a
BulletMagazinethat reloads or aRechargeableMagazinethat refills over time. No magazine means infinite ammo. - Recoil listens to the barrel and kicks the weapon back.
- Damage goes through the Modular Health System: every shot hurts the
Hitboxit hits.
All scripts are in the GlowingRifts.ModularWeaponSystem namespace.
๐ฆ Installation
- Import the Modular Health System from the Asset Store. The weapon system needs it for health, hitboxes and damage.
- Import the Modular Weapon System. It’s installed under
Assets/Glowing Rifts/Modular Weapon System. - Make sure the Input System package and the Universal Render Pipeline are installed. The example materials and shaders are made for URP.
- Add the components from Add Component > Glowing Rifts > Modular Weapon.
Laser Guide,Laser FollowerandMouse Followare under Glowing Rifts > Misc.
๐ซ Ready-Made Weapons
The Weapons folder has five weapons you can drag straight into a scene. They only use files from the Weapons folder, so you can delete Examples and keep them.
| Prefab | How it’s built |
|---|---|
Pistol | Raycast barrel, semi automatic, bullet magazine, recoil |
Shotgun | Dual weapon with a shotgun barrel, bullet magazine, recoil |
GrenadeRifle | Dual weapon: a raycast barrel, plus a projectile barrel firing explosive grenades |
RocketLauncher | Projectile barrel firing rockets you can steer with a Laser Guide |
LaserGun | Laser barrel with a Spool wind-up and a rechargeable magazine |
The building blocks (barrels, magazines, ammo, effects and an empty Weapon) are in Weapons/Prefabs.
๐งช Example Scenes
Open Examples/ModularWeaponSystem_Examples and pick an example. Press Escape in any example to come back. See Examples for each scene.
๐งฑ Your First Weapon
Add a Weapon
Add Weapon to the root of your weapon model. Turn on Use Built-In Input to fire with the mouse, or call StartShooting and StopShooting from your own input.
Add a Barrel
Add a barrel (for example Raycast Barrel) to a child of the weapon, and add a muzzle Transform to its Spawn Points, with the blue (Z) axis pointing forward. Set its Config: Fire Rate, Damage and Bullets Fired. Drag it into the Weapon’s Barrel field.
Add a Magazine
Add Bullet Magazine and drag it into the Weapon’s Magazine field. Leave the field empty for infinite ammo.
Hook the feedback
Use the barrel’s On Shot for the muzzle flash and sound, and its On Hit for impacts. Add Recoil above the barrel for kickback.
The Create Weapon guide builds the pistol step by step in the CreateWeapon scene.
Tip
Put targets on a layer the barrel’s Layers can hit, and give them a Health and Hitbox from the Modular Health System.